Skip to content

Commit

Permalink
feat(overlay): Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
marker dao ® committed Oct 4, 2024
1 parent 287412e commit af9b6f6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
2 changes: 0 additions & 2 deletions packages/devextreme/js/__internal/ui/overlay/m_overlay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1164,8 +1164,6 @@ const Overlay: typeof OverlayInstance = Widget.inherit({
case 'animation':
break;
case '_loopFocus':
this._toggleTabTerminator();
break;
case 'shading':
this._toggleShading(this.option('visible'));
this._toggleSafariScrolling();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2942,6 +2942,7 @@ QUnit.module('keyboard navigation', {
const instance = $element.dxLookup('instance');
const tabKeyDownEvent = $.Event('keydown', { key: 'Tab' });
const $overlayContent = $(instance.content()).parent();
// TODO: use getActiveElement
const $cancelButton = $overlayContent.find(CANCEL_BUTTON_SELECTOR);

$cancelButton.trigger(tabKeyDownEvent);
Expand All @@ -2964,6 +2965,7 @@ QUnit.module('keyboard navigation', {
const instance = $element.dxLookup('instance');
const tabKeyDownEvent = $.Event('keydown', { key: 'Tab', shiftKey: true });
const $overlayContent = $(instance.content()).parent();
// TODO: use getActiveElement
const $searchInput = $overlayContent.find(`.${LOOKUP_SEARCH_CLASS} .${TEXTEDITOR_INPUT_CLASS}`);

$searchInput.trigger(tabKeyDownEvent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3276,6 +3276,28 @@ testModule('focus policy', {
assert.strictEqual(getActiveElement(), $firstTabbable.get(0), 'first item focused on press tab on last item (does not go under overlay)');
});

test('focus in Overlay should be looped if _loopFocus: true and shading: false', function(assert) {
const overlay = new Overlay($('<div>').appendTo('#qunit-fixture'), {
visible: true,
shading: false,
_loopFocus: true,
contentTemplate: $('#focusableTemplate')
});
const $content = overlay.$content();

const $firstFocusableElement = $content.find('.firstTabbable');
const $lastFocusableElement = $content.find('.lastTabbable');

$lastFocusableElement.get(0).focus();
$($lastFocusableElement).trigger(this.tabEvent);

assert.strictEqual(getActiveElement(), $firstFocusableElement.get(0), 'first item is focused');

$($firstFocusableElement).trigger(this.shiftTabEvent);

assert.strictEqual(getActiveElement(), $lastFocusableElement.get(0), 'last item is focused');
});

test('elements under overlay with shader have not to get focus by tab when top overlay has no tabbable elements', function(assert) {
const overlay1 = new Overlay($('<div>').appendTo('#qunit-fixture'), {
shading: true,
Expand Down

0 comments on commit af9b6f6

Please sign in to comment.