Skip to content

Commit

Permalink
feat(filter-panel): ensure behavior works in modal and desktop (#7405)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkaeser committed Feb 1, 2022
1 parent 0c5e99c commit 366f0fb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import ddsSettings from '@carbon/ibmdotcom-utilities/es/utilities/settings/setti
import BXAccordionItem from 'carbon-web-components/es/components/accordion/accordion-item';
import styles from './filter-panel.scss';
import StableSelectorMixin from '../../globals/mixins/stable-selector';
import DDSFilterPanelComposite from './filter-panel-composite';

const { stablePrefix: ddsPrefix } = ddsSettings;
const { prefix } = settings;
Expand Down Expand Up @@ -137,13 +138,18 @@ class DDSFilterGroupItem extends StableSelectorMixin(BXAccordionItem) {
*/
protected _getCachedViewAllValue(): boolean {
const { titleText } = this;
let result: boolean = false;

const filterPanel = this.closest('dds-filter-panel');
if (filterPanel) {
// Indicates this is composite's duplicated content.
const shadowRoot = filterPanel?.parentNode as ShadowRoot;
const cache = (shadowRoot.host as DDSFilterPanelComposite)._filterGroupsAllRevealed;
const match = cache.find(entry => entry.id === titleText);
result = match ? match.value : false;
}

const cache = (((this.closest('dds-filter-panel')?.parentNode as ShadowRoot).host as HTMLElement) as any)
._filterGroupsAllRevealed;

const match = cache.find(entry => entry.id === titleText);

return match ? match.value : false;
return result;
}

protected firstUpdated(): void {
Expand All @@ -169,7 +175,7 @@ class DDSFilterGroupItem extends StableSelectorMixin(BXAccordionItem) {
if (prevAllRevealed === undefined) {
this._handleAllRevealed(this._getCachedViewAllValue());
} else {
this._handleAllRevealed(!prevAllRevealed);
this._handleAllRevealed(this.allRevealed);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,8 @@ class DDSFilterPanelComposite extends HostListenerMixin(StableSelectorMixin(LitE
});

if (match !== -1) {
// console.log('DEBUG: composite: Match found, setting cache to', event.detail.value);
this._filterGroupsAllRevealed[match].value = event.detail.value;
} else {
// console.log('DEBUG: composite: No match, setting cache to', event.detail.value);
this._filterGroupsAllRevealed.push(event.detail);
}
};
Expand Down

0 comments on commit 366f0fb

Please sign in to comment.