Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion src/components/utils/popover/popover-desktop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,11 @@ export class PopoverDesktop extends PopoverAbstract {
*/
protected override showNestedItems(item: PopoverItem): void {
if (this.nestedPopover !== null && this.nestedPopover !== undefined) {
return;
if (this.nestedPopoverTriggerItem === item) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please, add a jsdoc describing this statement

return;
}

this.destroyNestedPopoverIfExists();
}

this.nestedPopoverTriggerItem = item;
Expand Down Expand Up @@ -232,6 +236,8 @@ export class PopoverDesktop extends PopoverAbstract {
* Destroys existing nested popover
*/
protected destroyNestedPopoverIfExists(): void {
this.clearOpenedState();

if (this.nestedPopover === undefined || this.nestedPopover === null) {
return;
}
Expand Down Expand Up @@ -271,6 +277,7 @@ export class PopoverDesktop extends PopoverAbstract {

const nestedPopoverEl = this.nestedPopover.getElement();

this.clearOpenedState();
this.nodes.popover.appendChild(nestedPopoverEl);

this.setTriggerItemPosition(nestedPopoverEl, item);
Expand All @@ -281,9 +288,28 @@ export class PopoverDesktop extends PopoverAbstract {
this.nestedPopover.show();
this.flipper?.deactivate();

this.clearOpenedState();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why it is called twice in this context?

const triggerEl = item.getElement();
if (triggerEl) {
triggerEl.dataset.itemOpened = 'true';
triggerEl.setAttribute('aria-expanded', 'true');
}
Comment on lines +293 to +296
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jsdoc is required here


return this.nestedPopover;
}

/**
* Clears open-state markers from all popover items
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JSDoc repeats function name. Please, describe why we need this method instead.

*/
private clearOpenedState(): void {
this.nodes.popover
?.querySelectorAll<HTMLElement>('.ce-popover-item[data-item-opened]')
.forEach((el) => {
delete el.dataset.itemOpened;
el.removeAttribute('aria-expanded');
});
}

/**
* Checks if popover should be opened bottom.
* It should happen when there is enough space below or not enough space above
Expand Down