Skip to content

Commit

Permalink
List: Focus group header after interaction with header if collapsible…
Browse files Browse the repository at this point in the history
…Groups: true, skip invisible items
  • Loading branch information
marker-dao authored Nov 20, 2024
1 parent ca6ab57 commit 424b31a
Show file tree
Hide file tree
Showing 3 changed files with 222 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -388,12 +388,39 @@ const CollectionWidget = Widget.inherit({
this._updateParentActiveDescendant();
},

_getElementClassToSkipRefreshId: noop,

_shouldSkipRefreshId(target) {
const elementClass = this._getElementClassToSkipRefreshId() ?? '';
const shouldSkipRefreshId = $(target).hasClass(elementClass);

return shouldSkipRefreshId;
},

_refreshActiveDescendant($target) {
this.setAria('activedescendant', isDefined(this.option('focusedElement')) ? this.getFocusedItemId() : null, $target);
const { focusedElement } = this.option();

if (isDefined(focusedElement)) {
const shouldSetExistingId = this._shouldSkipRefreshId(focusedElement);
const id = shouldSetExistingId ? $(focusedElement).attr('id') : this.getFocusedItemId();

this.setAria('activedescendant', id, $target);

return;
}

this.setAria('activedescendant', null, $target);
},

_refreshItemId($target, needCleanItemId) {
if (!needCleanItemId && this.option('focusedElement')) {
const { focusedElement } = this.option();
const shouldSkipRefreshId = this._shouldSkipRefreshId($target);

if (shouldSkipRefreshId) {
return;
}

if (!needCleanItemId && focusedElement) {
this.setAria('id', this.getFocusedItemId(), $target);
} else {
this.setAria('id', null, $target);
Expand Down
21 changes: 17 additions & 4 deletions packages/devextreme/js/__internal/ui/list/m_list.base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ export const ListBase = CollectionWidget.inherit({

const $listGroup = this._getItemsContainer().children(`.${LIST_GROUP_CLASS}`);

const $items = $listGroup.find(itemAndHeaderSelector).filter(':visible');
const $items = $listGroup.find(itemAndHeaderSelector);

return $items;
},
Expand All @@ -314,7 +314,16 @@ export const ListBase = CollectionWidget.inherit({
const { collapsibleGroups } = this.option();

if (collapsibleGroups) {
return this._getItemAndHeaderElements();
const $elements = this._getItemAndHeaderElements();
const $visibleItems = $elements.filter((_, element) => {
if ($(element).hasClass(LIST_GROUP_HEADER_CLASS)) {
return true;
}

return !$(element).closest(`.${LIST_GROUP_CLASS}`).hasClass(LIST_GROUP_COLLAPSED_CLASS);
});

return $visibleItems;
}

return this.callBase($itemElements);
Expand Down Expand Up @@ -671,9 +680,9 @@ export const ListBase = CollectionWidget.inherit({
this._collapseGroupHandler($group);

if (focusStateEnabled) {
const listItemElement = getPublicElement($group.find(`.${LIST_ITEM_CLASS}`).eq(0));
const groupHeader = getPublicElement($group.find(`.${LIST_GROUP_HEADER_CLASS}`));

this.option({ focusedElement: listItemElement });
this.option({ focusedElement: groupHeader });
}
};

Expand Down Expand Up @@ -833,6 +842,10 @@ export const ListBase = CollectionWidget.inherit({
}
},

_getElementClassToSkipRefreshId() {
return LIST_GROUP_HEADER_CLASS;
},

_attachSwipeEvent($itemElement) {
const endEventName = addNamespace(swipeEventEnd, this.NAME);

Expand Down
Loading

0 comments on commit 424b31a

Please sign in to comment.