Skip to content

Commit 1e78858

Browse files
authored
TreeView: focus treeview element in selectAllEnabled and items empty (T1294524) (#30903)
1 parent fbce12e commit 1e78858

File tree

6 files changed

+17
-3
lines changed

6 files changed

+17
-3
lines changed
-80 Bytes
Loading
-19 Bytes
Loading
-688 Bytes
Loading

packages/devextreme/js/__internal/ui/tree_view/tree_view.base.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1912,7 +1912,8 @@ class TreeViewBase extends HierarchicalCollectionWidget<TreeViewBaseProperties,
19121912
}
19131913

19141914
focus(): void {
1915-
if (this._selectAllEnabled()) {
1915+
const { items = [] } = this.option();
1916+
if (this._selectAllEnabled() && items.length) {
19161917
// @ts-expect-error ts-error
19171918
eventsEngine.trigger(this._$selectAllItem, 'focus');
19181919
return;

packages/devextreme/js/__internal/ui/tree_view/tree_view.search.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import TextBox from '@ts/ui/text_box/m_text_box';
1111
import type { TreeViewBaseProperties } from '@ts/ui/tree_view/tree_view.base';
1212
import TreeViewBase from '@ts/ui/tree_view/tree_view.base';
1313

14-
const TREEVIEW_CLASS_PREFIX = 'dx-treeview';
14+
export const TREEVIEW_CLASS_PREFIX = 'dx-treeview';
1515
const TREEVIEW_NODE_CONTAINER_CLASS = 'dx-treeview-node-container';
1616

1717
SearchBoxController.setEditorClass(TextBox);
@@ -190,7 +190,8 @@ class TreeViewSearch extends TreeViewBase {
190190
_itemContainer(isSearchMode?: boolean, selectAllEnabled?: boolean): dxElementWrapper {
191191
const isSelectAllEnabled = selectAllEnabled ?? this._selectAllEnabled();
192192

193-
if (isSelectAllEnabled) {
193+
const { items = [] } = this.option();
194+
if (isSelectAllEnabled && items.length) {
194195
return this._getNodeContainer();
195196
}
196197

packages/devextreme/testing/tests/DevExpress.ui.widgets/treeViewParts/focusing.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import $ from 'jquery';
44
import { isRenderer } from 'core/utils/type';
55
import config from 'core/config';
6+
import { TREEVIEW_CLASS_PREFIX } from '__internal/ui/tree_view/tree_view.search';
67
import TreeViewTestWrapper from '../../../helpers/TreeViewTestHelper.js';
78
import keyboardMock from '../../../helpers/keyboardMock.js';
89
import { shouldSkipOnMobile } from '../../../helpers/device.js';
@@ -297,6 +298,17 @@ QUnit.test('select all item should be focused on treeview focus', function(asser
297298
assert.ok($selectAllItem.hasClass(FOCUSED_STATE_CLASS));
298299
});
299300

301+
QUnit.testInActiveWindow('Treeview container should be focused on empty treeview focus (T1294524)', function(assert) {
302+
const $treeView = initTree({
303+
showCheckBoxesMode: 'selectAll',
304+
focusStateEnabled: true,
305+
});
306+
307+
$treeView.dxTreeView('focus');
308+
309+
assert.strictEqual($treeView.hasClass(FOCUSED_STATE_CLASS), true, 'treeview is focused');
310+
});
311+
300312
QUnit.test('SelectAll checkbox should be checked with space key', function(assert) {
301313
if(shouldSkipOnMobile(assert)) {
302314
return;

0 commit comments

Comments
 (0)