Skip to content

Commit b0ce7c2

Browse files
r-farkhutdinovRuslan Farkhutdinov
andauthored
TagBox: Should not scroll page after re-render when fieldTemplate is passed (T1259996) (DevExpress#29201)
Co-authored-by: Ruslan Farkhutdinov <[email protected]>
1 parent 6cb734e commit b0ce7c2

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

packages/devextreme/js/__internal/ui/drop_down_editor/m_drop_down_editor.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { getPublicElement } from '@js/core/element';
66
import Guid from '@js/core/guid';
77
import $ from '@js/core/renderer';
88
import { FunctionTemplate } from '@js/core/templates/function_template';
9+
import browser from '@js/core/utils/browser';
910
import {
1011
noop,
1112
// @ts-expect-error
@@ -365,8 +366,19 @@ const DropDownEditor = TextBox.inherit({
365366
}
366367

367368
this._integrateInput();
368-
// @ts-expect-error
369-
isFocused && eventsEngine.trigger($input, 'focus');
369+
370+
if (!isFocused) {
371+
return;
372+
}
373+
374+
// T1259996
375+
if (browser.mozilla) {
376+
const inputElement = $input.get(0) as HTMLInputElement;
377+
inputElement.focus({ preventScroll: true });
378+
} else {
379+
// @ts-expect-error
380+
eventsEngine.trigger($input, 'focus');
381+
}
370382
},
371383
});
372384
},

packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/tagBox.tests.js

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import TagBox from 'ui/tag_box';
2020
import { normalizeKeyName } from 'events/utils/index';
2121
import { getWidth, getHeight } from 'core/utils/size';
2222
import Guid from 'core/guid';
23+
import browser from 'core/utils/browser';
2324

2425
import { TextEditorLabel } from '__internal/ui/text_box/m_text_editor.label';
2526

@@ -5425,11 +5426,38 @@ QUnit.module('the \'fieldTemplate\' option', moduleSetup, () => {
54255426
fieldTemplate: () => $('<div>').dxTextBox()
54265427
}).dxTagBox('instance');
54275428

5428-
$tagBox.find(`.${TAGBOX_TAG_REMOVE_BUTTON_CLASS }`).trigger('dxclick');
5429+
$tagBox.find(`.${TAGBOX_TAG_REMOVE_BUTTON_CLASS}`).trigger('dxclick');
54295430

54305431
assert.strictEqual(tagBox.option('value').length, 0);
54315432
assert.strictEqual(tagBoxWithFieldTemplate.option('value').length, 1);
54325433
});
5434+
5435+
QUnit.test('calls focus() with preventScroll: true when deleting a tag in Firefox (T1259996)', function(assert) {
5436+
if(!browser.mozilla) {
5437+
assert.ok(true, 'Only for Firefox');
5438+
return;
5439+
}
5440+
5441+
const items = Array.from({ length: 200 }, (_, i) => i + 1);
5442+
5443+
const focusSpy = sinon.spy(HTMLElement.prototype, 'focus');
5444+
5445+
const $tagBox = $('#tagBox').dxTagBox({
5446+
items,
5447+
value: items,
5448+
fieldTemplate: () => $('<div>').dxTextBox()
5449+
});
5450+
5451+
const $inputWrapper = $tagBox.find(`.${DROP_DOWN_EDITOR_INPUT_WRAPPER}`);
5452+
5453+
$inputWrapper.trigger('dxclick');
5454+
$tagBox.find(`.${TAGBOX_TAG_REMOVE_BUTTON_CLASS }`).trigger('dxclick');
5455+
5456+
assert.ok(focusSpy.calledTwice, 'focus() was called twice after click & deleting');
5457+
assert.deepEqual(focusSpy.args[1][0], { preventScroll: true }, 'focus() was called with preventScroll: true');
5458+
5459+
focusSpy.restore();
5460+
});
54335461
});
54345462

54355463
QUnit.module('the "customItemCreateEvent" option', {
@@ -8330,7 +8358,7 @@ QUnit.module('accessibility', () => {
83308358
});
83318359

83328360
QUnit.test('input should not have aria-labelledby attr if label is not specified', function(assert) {
8333-
const $tagBox = $('#tagBox').dxTagBox({ });
8361+
const $tagBox = $('#tagBox').dxTagBox({});
83348362
const $input = $tagBox.find(`.${TEXTEDITOR_INPUT_CLASS}`);
83358363

83368364
assert.strictEqual($input.attr('aria-labelledby'), undefined, 'aria-labelledby was set correctly');

0 commit comments

Comments
 (0)