Skip to content

Commit

Permalink
revert & add eventListeners
Browse files Browse the repository at this point in the history
  • Loading branch information
anveshmekala committed Sep 24, 2024
1 parent a45b1dc commit a5c193c
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions packages/calcite-components/src/components/dropdown/dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ export class Dropdown
<div
class="calcite-trigger-container"
id={`${guid}-menubutton`}
onClick={this.clickHandler}
onClick={this.openDropdown}
onKeyDown={this.keyDownHandler}
ref={this.setReferenceEl}
>
Expand Down Expand Up @@ -354,7 +354,7 @@ export class Dropdown
return;
}

this.clickHandler();
this.openDropdown();
}

@Listen("pointerleave")
Expand Down Expand Up @@ -543,7 +543,6 @@ export class Dropdown

onOpen(): void {
this.calciteDropdownOpen.emit();
this.focusOnFirstActiveOrDefaultItem();
}

onBeforeClose(): void {
Expand Down Expand Up @@ -589,11 +588,12 @@ export class Dropdown
}

if (isActivationKey(key)) {
this.clickHandler();
this.openDropdown();
event.preventDefault();
} else if (key === "ArrowDown" || key === "ArrowUp") {
this.focusLastDropdownItem = key === "ArrowUp";
this.open = true;
this.openDropdown();
event.preventDefault();
}
};

Expand Down Expand Up @@ -652,8 +652,16 @@ export class Dropdown
focusElement(target);
};

private clickHandler = (): void => {
private toggleOpenEnd = (): void => {
this.focusOnFirstActiveOrDefaultItem();
this.el.removeEventListener("calciteDropdownOpen", this.toggleOpenEnd);
};

private openDropdown = () => {
this.open = !this.open;
if (this.open) {
this.el.addEventListener("calciteDropdownOpen", this.toggleOpenEnd);
}
};

private updateTabIndexOfItems(target: HTMLCalciteDropdownItemElement): void {
Expand Down

0 comments on commit a5c193c

Please sign in to comment.