From 857b82723b2448d5a01f5327b2752ac421bab129 Mon Sep 17 00:00:00 2001 From: Raushen Date: Thu, 19 Nov 2026 15:34:38 +0200 Subject: [PATCH 01/13] Overlay, DropDownBox: do not scroll the page when focusing --- .../js/__internal/ui/drop_down_box.ts | 4 +-- .../js/__internal/ui/overlay/overlay.ts | 2 +- .../dropDownBox.tests.js | 24 +++++++++++++++ .../DevExpress.ui.widgets/overlay.tests.js | 30 +++++++++++++++++++ 4 files changed, 57 insertions(+), 3 deletions(-) diff --git a/packages/devextreme/js/__internal/ui/drop_down_box.ts b/packages/devextreme/js/__internal/ui/drop_down_box.ts index 3c5d9160e307..b1bed0882979 100644 --- a/packages/devextreme/js/__internal/ui/drop_down_box.ts +++ b/packages/devextreme/js/__internal/ui/drop_down_box.ts @@ -326,8 +326,8 @@ class DropDownBox< _popupShownHandler(): void { super._popupShownHandler(); - const $firstElement = this._getTabbableElements().first(); - eventsEngine.trigger($firstElement, 'focus'); + const firstElement = this._getTabbableElements().first().get(0); + firstElement?.focus({ preventScroll: true }); } _setCollectionWidgetOption(): void {} diff --git a/packages/devextreme/js/__internal/ui/overlay/overlay.ts b/packages/devextreme/js/__internal/ui/overlay/overlay.ts index 6802e814697a..031f40f547ae 100644 --- a/packages/devextreme/js/__internal/ui/overlay/overlay.ts +++ b/packages/devextreme/js/__internal/ui/overlay/overlay.ts @@ -724,7 +724,7 @@ class Overlay< const { focusStateEnabled } = this.option(); if (focusStateEnabled) { - eventsEngine.trigger(this._focusTarget(), 'focus'); + this._focusTarget()?.get(0)?.focus({ preventScroll: true }); } completeShowAnimation.call(this, element, config); diff --git a/packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/dropDownBox.tests.js b/packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/dropDownBox.tests.js index cf21256a1b08..b031448085d4 100644 --- a/packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/dropDownBox.tests.js +++ b/packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/dropDownBox.tests.js @@ -944,6 +944,30 @@ QUnit.module('keyboard navigation', moduleConfig, () => { assert.ok(inputFocusedHandler.callCount, 1, 'input get focused'); }); + QUnit.testInActiveWindow('first content element should be focused after popup opening without scrolling the page', function(assert) { + const $pageTail = $('
').height(window.innerHeight * 3).appendTo('body'); + const $input = $('', { type: 'text' }).css('marginTop', window.innerHeight); + + try { + const instance = new DropDownBox(this.$element, { + dropDownOptions: { maxHeight: window.innerHeight * 2 }, + contentTemplate(component, content) { + $(content).append($input); + } + }); + const pageScrollTop = window.scrollY; + + instance.open(); + + const inputBottomInPage = $input.get(0).getBoundingClientRect().bottom + window.scrollY; + assert.ok(inputBottomInPage > pageScrollTop + window.innerHeight, 'input is below the visible part of the page'); + assert.strictEqual(document.activeElement, $input.get(0), 'input is focused'); + assert.strictEqual(window.scrollY, pageScrollTop, 'page is not scrolled'); + } finally { + $pageTail.remove(); + } + }); + }); QUnit.module('validation', moduleConfig, () => { diff --git a/packages/devextreme/testing/tests/DevExpress.ui.widgets/overlay.tests.js b/packages/devextreme/testing/tests/DevExpress.ui.widgets/overlay.tests.js index 7f19d406318a..2bfe0b2d6406 100644 --- a/packages/devextreme/testing/tests/DevExpress.ui.widgets/overlay.tests.js +++ b/packages/devextreme/testing/tests/DevExpress.ui.widgets/overlay.tests.js @@ -3381,6 +3381,36 @@ testModule('keyboard navigation', { assert.strictEqual(this.overlay.option('visible'), true, 'overlay doesn\'t handle keyboard propagated events'); }); + + test('overlay content should get focus on show without scrolling the page', function(assert) { + const $pageTail = $('
').height(window.innerHeight * 3).appendTo('body'); + const $target = $('
') + .css({ position: 'absolute', top: window.innerHeight - 10, left: 0, width: 10, height: 10 }) + .appendTo('body'); + const overlay = new Overlay($('
').appendTo('body'), { + focusStateEnabled: true, + container: 'body', + width: 100, + height: 100, + position: { my: 'top left', at: 'bottom left', of: $target, collision: 'none' } + }); + const $overlayContent = $(overlay.$content()); + + try { + const pageScrollTop = window.scrollY; + + overlay.show(); + + const contentBottomInPage = $overlayContent.get(0).getBoundingClientRect().bottom + window.scrollY; + assert.ok(contentBottomInPage > pageScrollTop + window.innerHeight, 'overlay content is below the visible part of the page'); + assert.ok($overlayContent.is(getActiveElement()), 'overlay content is focused'); + assert.strictEqual(window.scrollY, pageScrollTop, 'page is not scrolled'); + } finally { + overlay.dispose(); + $target.remove(); + $pageTail.remove(); + } + }); }); testModule('focus policy', { From 332f7d156daac6cc5ef89892857473116d1dcbcf Mon Sep 17 00:00:00 2001 From: Raushen Date: Thu, 19 Nov 2026 16:15:55 +0200 Subject: [PATCH 02/13] Overlay tests: read focus from document.activeElement --- .../testing/tests/DevExpress.ui.widgets/overlay.tests.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/devextreme/testing/tests/DevExpress.ui.widgets/overlay.tests.js b/packages/devextreme/testing/tests/DevExpress.ui.widgets/overlay.tests.js index 2bfe0b2d6406..9913f4fc5d9b 100644 --- a/packages/devextreme/testing/tests/DevExpress.ui.widgets/overlay.tests.js +++ b/packages/devextreme/testing/tests/DevExpress.ui.widgets/overlay.tests.js @@ -3403,7 +3403,7 @@ testModule('keyboard navigation', { const contentBottomInPage = $overlayContent.get(0).getBoundingClientRect().bottom + window.scrollY; assert.ok(contentBottomInPage > pageScrollTop + window.innerHeight, 'overlay content is below the visible part of the page'); - assert.ok($overlayContent.is(getActiveElement()), 'overlay content is focused'); + assert.strictEqual(document.activeElement, $overlayContent.get(0), 'overlay content is focused'); assert.strictEqual(window.scrollY, pageScrollTop, 'page is not scrolled'); } finally { overlay.dispose(); From 883db51ebeadc540a0ff425ac9da18823644c7eb Mon Sep 17 00:00:00 2001 From: Raushen Date: Thu, 19 Nov 2026 16:32:40 +0200 Subject: [PATCH 03/13] Overlay, DropDownBox: keep focused element visible in popup --- .../js/__internal/ui/drop_down_box.ts | 3 +- .../js/__internal/ui/overlay/overlay.ts | 6 +++- .../js/__internal/ui/overlay/utils.ts | 31 +++++++++++++++++++ .../dropDownBox.tests.js | 19 ++++++++++++ .../DevExpress.ui.widgets/popover.tests.js | 22 +++++++++++++ 5 files changed, 79 insertions(+), 2 deletions(-) diff --git a/packages/devextreme/js/__internal/ui/drop_down_box.ts b/packages/devextreme/js/__internal/ui/drop_down_box.ts index b1bed0882979..5a545d3d8d3f 100644 --- a/packages/devextreme/js/__internal/ui/drop_down_box.ts +++ b/packages/devextreme/js/__internal/ui/drop_down_box.ts @@ -19,7 +19,7 @@ import type { OptionChanged } from '@ts/core/widget/types'; import eventsEngine from '@ts/events/core/events_engine'; import DropDownEditor, { type DropDownEditorInternalProperties } from '@ts/ui/drop_down_editor/drop_down_editor'; import type { PositioningEvent } from '@ts/ui/overlay/overlay'; -import { getElementMaxHeightByWindow } from '@ts/ui/overlay/utils'; +import { getElementMaxHeightByWindow, scrollIntoViewWithin } from '@ts/ui/overlay/utils'; import type { PopupProperties as InternalPopupProperties } from '@ts/ui/popup/popup'; const { getActiveElement } = domAdapter; @@ -328,6 +328,7 @@ class DropDownBox< super._popupShownHandler(); const firstElement = this._getTabbableElements().first().get(0); firstElement?.focus({ preventScroll: true }); + scrollIntoViewWithin(firstElement, this._popup?.$overlayContent()?.get(0)); } _setCollectionWidgetOption(): void {} diff --git a/packages/devextreme/js/__internal/ui/overlay/overlay.ts b/packages/devextreme/js/__internal/ui/overlay/overlay.ts index 031f40f547ae..fc7bb0dde382 100644 --- a/packages/devextreme/js/__internal/ui/overlay/overlay.ts +++ b/packages/devextreme/js/__internal/ui/overlay/overlay.ts @@ -57,6 +57,7 @@ import { OVERLAY_POSITION_ALIASES, OverlayPositionController, } from '@ts/ui/overlay/overlay_position_controller'; +import { scrollIntoViewWithin } from '@ts/ui/overlay/utils'; import * as zIndexPool from '@ts/ui/overlay/z_index'; import { themeModeChangedCallback } from '@ts/ui/themes_callback'; @@ -724,7 +725,10 @@ class Overlay< const { focusStateEnabled } = this.option(); if (focusStateEnabled) { - this._focusTarget()?.get(0)?.focus({ preventScroll: true }); + const focusTarget = this._focusTarget()?.get(0); + + focusTarget?.focus({ preventScroll: true }); + scrollIntoViewWithin(focusTarget, this._$content?.get(0)); } completeShowAnimation.call(this, element, config); diff --git a/packages/devextreme/js/__internal/ui/overlay/utils.ts b/packages/devextreme/js/__internal/ui/overlay/utils.ts index 94d08db98c0c..3e12695394b9 100644 --- a/packages/devextreme/js/__internal/ui/overlay/utils.ts +++ b/packages/devextreme/js/__internal/ui/overlay/utils.ts @@ -41,3 +41,34 @@ export const getElementMaxHeightByWindow = ( return actualOffset * WINDOW_HEIGHT_PERCENT; }; + +export const scrollIntoViewWithin = ( + element: HTMLElement | undefined, + container: HTMLElement | undefined, +): void => { + if (!element || !container) { + return; + } + + for ( + let parent = element.parentElement; + parent && container.contains(parent); + parent = parent.parentElement + ) { + const { overflowY } = getWindow().getComputedStyle(parent); + + if (overflowY !== 'visible' && overflowY !== 'clip') { + const elementRect = element.getBoundingClientRect(); + const parentRect = parent.getBoundingClientRect(); + + if (elementRect.top < parentRect.top) { + parent.scrollTop -= parentRect.top - elementRect.top; + } else if (elementRect.bottom > parentRect.bottom) { + parent.scrollTop += Math.min( + elementRect.bottom - parentRect.bottom, + elementRect.top - parentRect.top, + ); + } + } + } +}; diff --git a/packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/dropDownBox.tests.js b/packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/dropDownBox.tests.js index b031448085d4..1bc3d9dae786 100644 --- a/packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/dropDownBox.tests.js +++ b/packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/dropDownBox.tests.js @@ -968,6 +968,25 @@ QUnit.module('keyboard navigation', moduleConfig, () => { } }); + QUnit.testInActiveWindow('first content element should be scrolled into view inside the popup after popup opening', function(assert) { + const $input = $('', { type: 'text' }); + + const instance = new DropDownBox(this.$element, { + dropDownOptions: { height: 200 }, + contentTemplate(component, content) { + $(content).append($('
').height(400), $input); + } + }); + + instance.open(); + + const inputRect = $input.get(0).getBoundingClientRect(); + const overlayContentRect = $(instance.content()).parent(`.${OVERLAY_CONTENT_CLASS}`).get(0).getBoundingClientRect(); + + assert.strictEqual(document.activeElement, $input.get(0), 'input is focused'); + assert.ok(Math.round(inputRect.top) >= Math.round(overlayContentRect.top) && Math.round(inputRect.bottom) <= Math.round(overlayContentRect.bottom), 'input is in the visible part of the popup'); + }); + }); QUnit.module('validation', moduleConfig, () => { diff --git a/packages/devextreme/testing/tests/DevExpress.ui.widgets/popover.tests.js b/packages/devextreme/testing/tests/DevExpress.ui.widgets/popover.tests.js index 229fee29c9ed..e0bd37dbf8aa 100644 --- a/packages/devextreme/testing/tests/DevExpress.ui.widgets/popover.tests.js +++ b/packages/devextreme/testing/tests/DevExpress.ui.widgets/popover.tests.js @@ -3255,6 +3255,28 @@ QUnit.module('accessibility', { assert.strictEqual(document.activeElement, $input1.get(0), 'first tabbable element is focused'); }); + QUnit.test('Popover in dialog mode should scroll the first tabbable element into view inside content on show', function(assert) { + const instance = new Popover(this.$element, { + target: this.$target, + height: 200, + contentTemplate: function() { + return $('
').append($('
').height(400), $('', { id: 'input1' })); + }, + toolbarItems: [{ text: 'OK' }], + visible: false, + }); + + instance.show(); + this.clock.tick(500); + + const input = $('#input1').get(0); + const inputRect = input.getBoundingClientRect(); + const contentRect = instance.$content().get(0).getBoundingClientRect(); + + assert.strictEqual(document.activeElement, input, 'first tabbable element is focused'); + assert.ok(Math.round(inputRect.top) >= Math.round(contentRect.top) && Math.round(inputRect.bottom) <= Math.round(contentRect.bottom), 'first tabbable element is in the visible part of the content'); + }); + QUnit.test('Popover in dialog mode should restore focus to target on dispose when visible', function(assert) { this.$target.attr('tabindex', 0).focus(); From b5e33ad8f1bf75af4d8a6cc5fabd65324ad25007 Mon Sep 17 00:00:00 2001 From: Raushen Date: Thu, 19 Nov 2026 16:42:41 +0200 Subject: [PATCH 04/13] Overlay: prevent focus scroll only with hideOnParentScroll --- .../js/__internal/ui/overlay/overlay.ts | 4 +- .../DevExpress.ui.widgets/overlay.tests.js | 56 ++++++++++--------- 2 files changed, 33 insertions(+), 27 deletions(-) diff --git a/packages/devextreme/js/__internal/ui/overlay/overlay.ts b/packages/devextreme/js/__internal/ui/overlay/overlay.ts index fc7bb0dde382..14f1cbb845ad 100644 --- a/packages/devextreme/js/__internal/ui/overlay/overlay.ts +++ b/packages/devextreme/js/__internal/ui/overlay/overlay.ts @@ -722,12 +722,12 @@ class Overlay< return; } - const { focusStateEnabled } = this.option(); + const { focusStateEnabled, hideOnParentScroll } = this.option(); if (focusStateEnabled) { const focusTarget = this._focusTarget()?.get(0); - focusTarget?.focus({ preventScroll: true }); + focusTarget?.focus({ preventScroll: Boolean(hideOnParentScroll) }); scrollIntoViewWithin(focusTarget, this._$content?.get(0)); } diff --git a/packages/devextreme/testing/tests/DevExpress.ui.widgets/overlay.tests.js b/packages/devextreme/testing/tests/DevExpress.ui.widgets/overlay.tests.js index 9913f4fc5d9b..00e6245d2c83 100644 --- a/packages/devextreme/testing/tests/DevExpress.ui.widgets/overlay.tests.js +++ b/packages/devextreme/testing/tests/DevExpress.ui.widgets/overlay.tests.js @@ -3382,34 +3382,40 @@ testModule('keyboard navigation', { assert.strictEqual(this.overlay.option('visible'), true, 'overlay doesn\'t handle keyboard propagated events'); }); - test('overlay content should get focus on show without scrolling the page', function(assert) { - const $pageTail = $('
').height(window.innerHeight * 3).appendTo('body'); - const $target = $('
') - .css({ position: 'absolute', top: window.innerHeight - 10, left: 0, width: 10, height: 10 }) - .appendTo('body'); - const overlay = new Overlay($('
').appendTo('body'), { - focusStateEnabled: true, - container: 'body', - width: 100, - height: 100, - position: { my: 'top left', at: 'bottom left', of: $target, collision: 'none' } - }); - const $overlayContent = $(overlay.$content()); - - try { + [ + { hideOnParentScroll: true, isPageScrolled: false }, + { hideOnParentScroll: false, isPageScrolled: true }, + ].forEach(({ hideOnParentScroll, isPageScrolled }) => { + test(`overlay content should get focus on show and ${isPageScrolled ? 'scroll' : 'not scroll'} the page when hideOnParentScroll is ${hideOnParentScroll}`, function(assert) { + const $pageTail = $('
').height(window.innerHeight * 3).appendTo('body'); + const $target = $('
') + .css({ position: 'absolute', top: window.innerHeight - 10, left: 0, width: 10, height: 10 }) + .appendTo('body'); + const overlay = new Overlay($('
').appendTo('body'), { + focusStateEnabled: true, + hideOnParentScroll, + container: 'body', + width: 100, + height: 100, + position: { my: 'top left', at: 'bottom left', of: $target, collision: 'none' } + }); + const $overlayContent = $(overlay.$content()); const pageScrollTop = window.scrollY; - overlay.show(); + try { + overlay.show(); - const contentBottomInPage = $overlayContent.get(0).getBoundingClientRect().bottom + window.scrollY; - assert.ok(contentBottomInPage > pageScrollTop + window.innerHeight, 'overlay content is below the visible part of the page'); - assert.strictEqual(document.activeElement, $overlayContent.get(0), 'overlay content is focused'); - assert.strictEqual(window.scrollY, pageScrollTop, 'page is not scrolled'); - } finally { - overlay.dispose(); - $target.remove(); - $pageTail.remove(); - } + const contentBottomInPage = $overlayContent.get(0).getBoundingClientRect().bottom + window.scrollY; + assert.ok(contentBottomInPage > pageScrollTop + window.innerHeight, 'overlay content is below the visible part of the page'); + assert.strictEqual(document.activeElement, $overlayContent.get(0), 'overlay content is focused'); + assert.strictEqual(window.scrollY > pageScrollTop, isPageScrolled, 'page is scrolled'); + } finally { + overlay.dispose(); + $target.remove(); + $pageTail.remove(); + window.scrollTo(0, pageScrollTop); + } + }); }); }); From 0ff33085564ce5135113f1ff25eb8eba4391a2c5 Mon Sep 17 00:00:00 2001 From: Raushen Date: Thu, 19 Nov 2026 16:55:48 +0200 Subject: [PATCH 05/13] DropDownBox tests: check the first of two tabbable elements --- .../tests/DevExpress.ui.widgets.editors/dropDownBox.tests.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/dropDownBox.tests.js b/packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/dropDownBox.tests.js index 1bc3d9dae786..26077d72f27b 100644 --- a/packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/dropDownBox.tests.js +++ b/packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/dropDownBox.tests.js @@ -947,12 +947,13 @@ QUnit.module('keyboard navigation', moduleConfig, () => { QUnit.testInActiveWindow('first content element should be focused after popup opening without scrolling the page', function(assert) { const $pageTail = $('
').height(window.innerHeight * 3).appendTo('body'); const $input = $('', { type: 'text' }).css('marginTop', window.innerHeight); + const $nextInput = $('', { type: 'text' }); try { const instance = new DropDownBox(this.$element, { dropDownOptions: { maxHeight: window.innerHeight * 2 }, contentTemplate(component, content) { - $(content).append($input); + $('
').append($input, $nextInput).appendTo(content); } }); const pageScrollTop = window.scrollY; From c21c39cb75f69340a3d194ea268f8e2b3b66c874 Mon Sep 17 00:00:00 2001 From: Raushen Date: Thu, 19 Nov 2026 18:35:50 +0200 Subject: [PATCH 06/13] Overlay: reveal the focused element horizontally in popup --- .../js/__internal/ui/overlay/utils.ts | 53 ++++++++++++++----- .../dropDownBox.tests.js | 20 +++++++ 2 files changed, 59 insertions(+), 14 deletions(-) diff --git a/packages/devextreme/js/__internal/ui/overlay/utils.ts b/packages/devextreme/js/__internal/ui/overlay/utils.ts index 3e12695394b9..d4f7deb5ee6d 100644 --- a/packages/devextreme/js/__internal/ui/overlay/utils.ts +++ b/packages/devextreme/js/__internal/ui/overlay/utils.ts @@ -42,6 +42,25 @@ export const getElementMaxHeightByWindow = ( return actualOffset * WINDOW_HEIGHT_PERCENT; }; +const isScrollableOverflow = (overflow: string): boolean => overflow !== 'visible' && overflow !== 'clip'; + +const getScrollDelta = ( + start: number, + end: number, + viewStart: number, + viewEnd: number, +): number => { + if (start < viewStart) { + return start - viewStart; + } + + if (end > viewEnd) { + return Math.min(end - viewEnd, start - viewStart); + } + + return 0; +}; + export const scrollIntoViewWithin = ( element: HTMLElement | undefined, container: HTMLElement | undefined, @@ -55,20 +74,26 @@ export const scrollIntoViewWithin = ( parent && container.contains(parent); parent = parent.parentElement ) { - const { overflowY } = getWindow().getComputedStyle(parent); - - if (overflowY !== 'visible' && overflowY !== 'clip') { - const elementRect = element.getBoundingClientRect(); - const parentRect = parent.getBoundingClientRect(); - - if (elementRect.top < parentRect.top) { - parent.scrollTop -= parentRect.top - elementRect.top; - } else if (elementRect.bottom > parentRect.bottom) { - parent.scrollTop += Math.min( - elementRect.bottom - parentRect.bottom, - elementRect.top - parentRect.top, - ); - } + const { overflowX, overflowY } = getWindow().getComputedStyle(parent); + const elementRect = element.getBoundingClientRect(); + const parentRect = parent.getBoundingClientRect(); + + if (isScrollableOverflow(overflowY)) { + parent.scrollTop += getScrollDelta( + elementRect.top, + elementRect.bottom, + parentRect.top, + parentRect.bottom, + ); + } + + if (isScrollableOverflow(overflowX)) { + parent.scrollLeft += getScrollDelta( + elementRect.left, + elementRect.right, + parentRect.left, + parentRect.right, + ); } } }; diff --git a/packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/dropDownBox.tests.js b/packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/dropDownBox.tests.js index 26077d72f27b..4c18aec6adda 100644 --- a/packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/dropDownBox.tests.js +++ b/packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/dropDownBox.tests.js @@ -988,6 +988,26 @@ QUnit.module('keyboard navigation', moduleConfig, () => { assert.ok(Math.round(inputRect.top) >= Math.round(overlayContentRect.top) && Math.round(inputRect.bottom) <= Math.round(overlayContentRect.bottom), 'input is in the visible part of the popup'); }); + QUnit.testInActiveWindow('first content element should be scrolled into view horizontally inside the popup after popup opening', function(assert) { + const $input = $('', { type: 'text' }).css('width', 50); + const $scroller = $('
').css({ overflowX: 'auto', whiteSpace: 'nowrap' }); + + const instance = new DropDownBox(this.$element, { + dropDownOptions: { width: 200 }, + contentTemplate(component, content) { + $scroller.append($('').css({ display: 'inline-block', width: 400 }), $input).appendTo(content); + } + }); + + instance.open(); + + const inputRect = $input.get(0).getBoundingClientRect(); + const scrollerRect = $scroller.get(0).getBoundingClientRect(); + + assert.strictEqual(document.activeElement, $input.get(0), 'input is focused'); + assert.ok(Math.round(inputRect.left) >= Math.round(scrollerRect.left) && Math.round(inputRect.right) <= Math.round(scrollerRect.right), 'input is in the visible part of the scroller'); + }); + }); QUnit.module('validation', moduleConfig, () => { From e45a4ebe1b2b38437bb77540836f95d80bae0f3f Mon Sep 17 00:00:00 2001 From: Raushen Date: Thu, 19 Nov 2026 18:38:39 +0200 Subject: [PATCH 07/13] Overlay: reveal the focused element within the client area --- .../js/__internal/ui/overlay/utils.ts | 10 ++++++---- .../dropDownBox.tests.js | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/packages/devextreme/js/__internal/ui/overlay/utils.ts b/packages/devextreme/js/__internal/ui/overlay/utils.ts index d4f7deb5ee6d..18a65e2f209f 100644 --- a/packages/devextreme/js/__internal/ui/overlay/utils.ts +++ b/packages/devextreme/js/__internal/ui/overlay/utils.ts @@ -77,13 +77,15 @@ export const scrollIntoViewWithin = ( const { overflowX, overflowY } = getWindow().getComputedStyle(parent); const elementRect = element.getBoundingClientRect(); const parentRect = parent.getBoundingClientRect(); + const viewTop = parentRect.top + parent.clientTop; + const viewLeft = parentRect.left + parent.clientLeft; if (isScrollableOverflow(overflowY)) { parent.scrollTop += getScrollDelta( elementRect.top, elementRect.bottom, - parentRect.top, - parentRect.bottom, + viewTop, + viewTop + parent.clientHeight, ); } @@ -91,8 +93,8 @@ export const scrollIntoViewWithin = ( parent.scrollLeft += getScrollDelta( elementRect.left, elementRect.right, - parentRect.left, - parentRect.right, + viewLeft, + viewLeft + parent.clientWidth, ); } } diff --git a/packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/dropDownBox.tests.js b/packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/dropDownBox.tests.js index 4c18aec6adda..9d9db9878e13 100644 --- a/packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/dropDownBox.tests.js +++ b/packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/dropDownBox.tests.js @@ -1008,6 +1008,25 @@ QUnit.module('keyboard navigation', moduleConfig, () => { assert.ok(Math.round(inputRect.left) >= Math.round(scrollerRect.left) && Math.round(inputRect.right) <= Math.round(scrollerRect.right), 'input is in the visible part of the scroller'); }); + QUnit.testInActiveWindow('first content element should not stay under the border of a scroller inside the popup after popup opening', function(assert) { + const $input = $('', { type: 'text' }).css('display', 'block'); + const $scroller = $('
').css({ height: 100, overflowY: 'auto', borderBottom: '20px solid' }); + + const instance = new DropDownBox(this.$element, { + contentTemplate(component, content) { + $scroller.append($('
').height(300), $input).appendTo(content); + } + }); + + instance.open(); + + const inputRect = $input.get(0).getBoundingClientRect(); + const elementAtInputBottom = document.elementFromPoint(inputRect.left + inputRect.width / 2, inputRect.bottom - 1); + + assert.strictEqual(document.activeElement, $input.get(0), 'input is focused'); + assert.strictEqual(elementAtInputBottom, $input.get(0), 'input bottom edge is visible'); + }); + }); QUnit.module('validation', moduleConfig, () => { From d60e0a5bdc54220332f471e0c158746e78296bb8 Mon Sep 17 00:00:00 2001 From: Raushen Date: Thu, 19 Nov 2026 19:05:22 +0200 Subject: [PATCH 08/13] DropDownBox tests: check the inner input is focused once --- .../tests/DevExpress.ui.widgets.editors/dropDownBox.tests.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/dropDownBox.tests.js b/packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/dropDownBox.tests.js index 9d9db9878e13..08ffeb308f45 100644 --- a/packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/dropDownBox.tests.js +++ b/packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/dropDownBox.tests.js @@ -941,7 +941,7 @@ QUnit.module('keyboard navigation', moduleConfig, () => { instance.open(); - assert.ok(inputFocusedHandler.callCount, 1, 'input get focused'); + assert.strictEqual(inputFocusedHandler.callCount, 1, 'input get focused'); }); QUnit.testInActiveWindow('first content element should be focused after popup opening without scrolling the page', function(assert) { From 29d401531e19a57961328c18cd5b318da191343e Mon Sep 17 00:00:00 2001 From: Raushen Date: Thu, 19 Nov 2026 19:21:56 +0200 Subject: [PATCH 09/13] Overlay: account for scaled containers when revealing focus --- .../js/__internal/ui/overlay/utils.ts | 14 +++++++------ .../dropDownBox.tests.js | 20 +++++++++++++++++++ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/packages/devextreme/js/__internal/ui/overlay/utils.ts b/packages/devextreme/js/__internal/ui/overlay/utils.ts index 18a65e2f209f..f94182fd029c 100644 --- a/packages/devextreme/js/__internal/ui/overlay/utils.ts +++ b/packages/devextreme/js/__internal/ui/overlay/utils.ts @@ -77,16 +77,18 @@ export const scrollIntoViewWithin = ( const { overflowX, overflowY } = getWindow().getComputedStyle(parent); const elementRect = element.getBoundingClientRect(); const parentRect = parent.getBoundingClientRect(); - const viewTop = parentRect.top + parent.clientTop; - const viewLeft = parentRect.left + parent.clientLeft; + const scaleX = parent.offsetWidth ? parentRect.width / parent.offsetWidth : 1; + const scaleY = parent.offsetHeight ? parentRect.height / parent.offsetHeight : 1; + const viewTop = parentRect.top + parent.clientTop * scaleY; + const viewLeft = parentRect.left + parent.clientLeft * scaleX; if (isScrollableOverflow(overflowY)) { parent.scrollTop += getScrollDelta( elementRect.top, elementRect.bottom, viewTop, - viewTop + parent.clientHeight, - ); + viewTop + parent.clientHeight * scaleY, + ) / scaleY; } if (isScrollableOverflow(overflowX)) { @@ -94,8 +96,8 @@ export const scrollIntoViewWithin = ( elementRect.left, elementRect.right, viewLeft, - viewLeft + parent.clientWidth, - ); + viewLeft + parent.clientWidth * scaleX, + ) / scaleX; } } }; diff --git a/packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/dropDownBox.tests.js b/packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/dropDownBox.tests.js index 08ffeb308f45..a302ae445c5a 100644 --- a/packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/dropDownBox.tests.js +++ b/packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/dropDownBox.tests.js @@ -1027,6 +1027,26 @@ QUnit.module('keyboard navigation', moduleConfig, () => { assert.strictEqual(elementAtInputBottom, $input.get(0), 'input bottom edge is visible'); }); + QUnit.testInActiveWindow('first content element should be scrolled into view inside a scaled scroller in the popup after popup opening', function(assert) { + const $input = $('', { type: 'text' }).css({ display: 'inline-block', width: 50 }); + const $scroller = $('
').css({ width: 100, height: 100, overflow: 'auto', whiteSpace: 'nowrap' }); + + const instance = new DropDownBox(this.$element, { + contentTemplate(component, content) { + $scroller.append($('
').height(300), $('').css({ display: 'inline-block', width: 400 }), $input); + $('
').css({ transform: 'scale(0.5)', transformOrigin: '0 0' }).append($scroller).appendTo(content); + } + }); + + instance.open(); + + const inputRect = $input.get(0).getBoundingClientRect(); + const elementAtInputCorner = document.elementFromPoint(inputRect.right - 1, inputRect.bottom - 1); + + assert.strictEqual(document.activeElement, $input.get(0), 'input is focused'); + assert.strictEqual(elementAtInputCorner, $input.get(0), 'input bottom right corner is visible'); + }); + }); QUnit.module('validation', moduleConfig, () => { From ecd91a979465457d1fc253e84fd0388a1d4300d4 Mon Sep 17 00:00:00 2001 From: Raushen Date: Thu, 19 Nov 2026 19:45:36 +0200 Subject: [PATCH 10/13] Overlay: scroll each container once when revealing focus --- .../js/__internal/ui/overlay/utils.ts | 19 ++++++++------- .../dropDownBox.tests.js | 23 +++++++++++++++++++ 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/packages/devextreme/js/__internal/ui/overlay/utils.ts b/packages/devextreme/js/__internal/ui/overlay/utils.ts index f94182fd029c..b6b4be84f8de 100644 --- a/packages/devextreme/js/__internal/ui/overlay/utils.ts +++ b/packages/devextreme/js/__internal/ui/overlay/utils.ts @@ -82,22 +82,25 @@ export const scrollIntoViewWithin = ( const viewTop = parentRect.top + parent.clientTop * scaleY; const viewLeft = parentRect.left + parent.clientLeft * scaleX; - if (isScrollableOverflow(overflowY)) { - parent.scrollTop += getScrollDelta( + const top = isScrollableOverflow(overflowY) + ? getScrollDelta( elementRect.top, elementRect.bottom, viewTop, viewTop + parent.clientHeight * scaleY, - ) / scaleY; - } - - if (isScrollableOverflow(overflowX)) { - parent.scrollLeft += getScrollDelta( + ) / scaleY + : 0; + const left = isScrollableOverflow(overflowX) + ? getScrollDelta( elementRect.left, elementRect.right, viewLeft, viewLeft + parent.clientWidth * scaleX, - ) / scaleX; + ) / scaleX + : 0; + + if (top || left) { + parent.scrollTo({ top: parent.scrollTop + top, left: parent.scrollLeft + left }); } } }; diff --git a/packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/dropDownBox.tests.js b/packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/dropDownBox.tests.js index a302ae445c5a..639fe83681ba 100644 --- a/packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/dropDownBox.tests.js +++ b/packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/dropDownBox.tests.js @@ -1047,6 +1047,29 @@ QUnit.module('keyboard navigation', moduleConfig, () => { assert.strictEqual(elementAtInputCorner, $input.get(0), 'input bottom right corner is visible'); }); + QUnit.testInActiveWindow('first content element should be scrolled into view inside a smoothly scrolling scroller in the popup after popup opening', function(assert) { + const done = assert.async(); + const $input = $('', { type: 'text' }).css({ display: 'inline-block', width: 50 }); + const $scroller = $('
').css({ width: 100, height: 100, overflow: 'auto', whiteSpace: 'nowrap', scrollBehavior: 'smooth' }); + + const instance = new DropDownBox(this.$element, { + contentTemplate(component, content) { + $scroller.append($('
').height(300), $('').css({ display: 'inline-block', width: 400 }), $input).appendTo(content); + } + }); + + $scroller.get(0).addEventListener('scrollend', () => { + const inputRect = $input.get(0).getBoundingClientRect(); + const elementAtInputCorner = document.elementFromPoint(inputRect.right - 1, inputRect.bottom - 1); + + assert.strictEqual(document.activeElement, $input.get(0), 'input is focused'); + assert.strictEqual(elementAtInputCorner, $input.get(0), 'input bottom right corner is visible'); + done(); + }, { once: true }); + + instance.open(); + }); + }); QUnit.module('validation', moduleConfig, () => { From 9b28ea84e8814153e88f2eda99b7623557c44733 Mon Sep 17 00:00:00 2001 From: Raushen Date: Thu, 19 Nov 2026 20:56:45 +0200 Subject: [PATCH 11/13] Overlay: account for nested smooth scrolling on focus --- .../js/__internal/ui/overlay/utils.ts | 24 ++++++++---- .../dropDownBox.tests.js | 39 +++++++++++++++++++ 2 files changed, 55 insertions(+), 8 deletions(-) diff --git a/packages/devextreme/js/__internal/ui/overlay/utils.ts b/packages/devextreme/js/__internal/ui/overlay/utils.ts index b6b4be84f8de..ea47c87568ab 100644 --- a/packages/devextreme/js/__internal/ui/overlay/utils.ts +++ b/packages/devextreme/js/__internal/ui/overlay/utils.ts @@ -69,13 +69,16 @@ export const scrollIntoViewWithin = ( return; } + const elementRect = element.getBoundingClientRect(); + let shiftTop = 0; + let shiftLeft = 0; + for ( let parent = element.parentElement; parent && container.contains(parent); parent = parent.parentElement ) { const { overflowX, overflowY } = getWindow().getComputedStyle(parent); - const elementRect = element.getBoundingClientRect(); const parentRect = parent.getBoundingClientRect(); const scaleX = parent.offsetWidth ? parentRect.width / parent.offsetWidth : 1; const scaleY = parent.offsetHeight ? parentRect.height / parent.offsetHeight : 1; @@ -84,23 +87,28 @@ export const scrollIntoViewWithin = ( const top = isScrollableOverflow(overflowY) ? getScrollDelta( - elementRect.top, - elementRect.bottom, + elementRect.top - shiftTop, + elementRect.bottom - shiftTop, viewTop, viewTop + parent.clientHeight * scaleY, - ) / scaleY + ) : 0; const left = isScrollableOverflow(overflowX) ? getScrollDelta( - elementRect.left, - elementRect.right, + elementRect.left - shiftLeft, + elementRect.right - shiftLeft, viewLeft, viewLeft + parent.clientWidth * scaleX, - ) / scaleX + ) : 0; if (top || left) { - parent.scrollTo({ top: parent.scrollTop + top, left: parent.scrollLeft + left }); + parent.scrollTo({ + top: parent.scrollTop + top / scaleY, + left: parent.scrollLeft + left / scaleX, + }); + shiftTop += top; + shiftLeft += left; } } }; diff --git a/packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/dropDownBox.tests.js b/packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/dropDownBox.tests.js index 639fe83681ba..561f07243dcc 100644 --- a/packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/dropDownBox.tests.js +++ b/packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/dropDownBox.tests.js @@ -1070,6 +1070,45 @@ QUnit.module('keyboard navigation', moduleConfig, () => { instance.open(); }); + QUnit.testInActiveWindow('first content element should be scrolled into view inside nested smoothly scrolling scrollers in the popup after popup opening', function(assert) { + const done = assert.async(); + const $input = $('', { type: 'text' }).css({ display: 'inline-block', width: 50 }); + const $innerScroller = $('
').css({ display: 'inline-block', width: 100, height: 100, overflow: 'auto', whiteSpace: 'nowrap', scrollBehavior: 'smooth' }); + const $outerScroller = $('
').css({ width: 150, height: 150, overflow: 'auto', whiteSpace: 'nowrap', scrollBehavior: 'smooth' }); + let pendingScrollEndCount = 2; + + const instance = new DropDownBox(this.$element, { + contentTemplate(component, content) { + $innerScroller.append($('
').height(300), $('').css({ display: 'inline-block', width: 400 }), $input); + $outerScroller.append( + $('
').height(300), + $('').css({ display: 'inline-block', width: 300 }), + $innerScroller, + $('
').css({ width: 900, height: 600 }) + ).appendTo(content); + } + }); + + [$innerScroller, $outerScroller].forEach(($scroller) => { + $scroller.get(0).addEventListener('scrollend', () => { + pendingScrollEndCount -= 1; + + if(pendingScrollEndCount) { + return; + } + + const inputRect = $input.get(0).getBoundingClientRect(); + const elementAtInputCorner = document.elementFromPoint(inputRect.right - 1, inputRect.bottom - 1); + + assert.strictEqual(document.activeElement, $input.get(0), 'input is focused'); + assert.strictEqual(elementAtInputCorner, $input.get(0), 'input bottom right corner is visible'); + done(); + }, { once: true }); + }); + + instance.open(); + }); + }); QUnit.module('validation', moduleConfig, () => { From 8d84f473ec7d2b5f60c3f1b1e187353bb40e2b89 Mon Sep 17 00:00:00 2001 From: Raushen Date: Thu, 19 Nov 2026 21:49:43 +0200 Subject: [PATCH 12/13] Overlay: skip revealing focus when there is no window --- packages/devextreme/js/__internal/ui/overlay/utils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/devextreme/js/__internal/ui/overlay/utils.ts b/packages/devextreme/js/__internal/ui/overlay/utils.ts index ea47c87568ab..52f88ad11588 100644 --- a/packages/devextreme/js/__internal/ui/overlay/utils.ts +++ b/packages/devextreme/js/__internal/ui/overlay/utils.ts @@ -2,7 +2,7 @@ import type { dxElementWrapper } from '@js/core/renderer'; import $ from '@js/core/renderer'; import { getInnerHeight, getOuterHeight } from '@js/core/utils/size'; import { isNumeric } from '@js/core/utils/type'; -import { getWindow } from '@ts/core/utils/window'; +import { getWindow, hasWindow } from '@ts/core/utils/window'; const WINDOW_HEIGHT_PERCENT = 0.9; @@ -65,7 +65,7 @@ export const scrollIntoViewWithin = ( element: HTMLElement | undefined, container: HTMLElement | undefined, ): void => { - if (!element || !container) { + if (!element || !container || !hasWindow()) { return; } From ee5e45e1a781da091325fe3cbdc20765c16f543d Mon Sep 17 00:00:00 2001 From: Raushen Date: Thu, 19 Nov 2026 21:49:50 +0200 Subject: [PATCH 13/13] DropDownBox tests: check focus before smooth scroll ends --- .../DevExpress.ui.widgets.editors/dropDownBox.tests.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/dropDownBox.tests.js b/packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/dropDownBox.tests.js index 561f07243dcc..8f50bcceebfb 100644 --- a/packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/dropDownBox.tests.js +++ b/packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/dropDownBox.tests.js @@ -1062,12 +1062,13 @@ QUnit.module('keyboard navigation', moduleConfig, () => { const inputRect = $input.get(0).getBoundingClientRect(); const elementAtInputCorner = document.elementFromPoint(inputRect.right - 1, inputRect.bottom - 1); - assert.strictEqual(document.activeElement, $input.get(0), 'input is focused'); assert.strictEqual(elementAtInputCorner, $input.get(0), 'input bottom right corner is visible'); done(); }, { once: true }); instance.open(); + + assert.strictEqual(document.activeElement, $input.get(0), 'input is focused'); }); QUnit.testInActiveWindow('first content element should be scrolled into view inside nested smoothly scrolling scrollers in the popup after popup opening', function(assert) { @@ -1100,13 +1101,14 @@ QUnit.module('keyboard navigation', moduleConfig, () => { const inputRect = $input.get(0).getBoundingClientRect(); const elementAtInputCorner = document.elementFromPoint(inputRect.right - 1, inputRect.bottom - 1); - assert.strictEqual(document.activeElement, $input.get(0), 'input is focused'); assert.strictEqual(elementAtInputCorner, $input.get(0), 'input bottom right corner is visible'); done(); }, { once: true }); }); instance.open(); + + assert.strictEqual(document.activeElement, $input.get(0), 'input is focused'); }); });