Skip to content

Commit

Permalink
fix(dropdown): close dropdown when an item is clicked (#533)
Browse files Browse the repository at this point in the history
  • Loading branch information
abugraokkali authored Apr 20, 2023
1 parent 6dc5397 commit f78477b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/components/dropdown/bl-dropdown.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,32 @@ describe('bl-dropdown', () => {
});
});

it('should close dropdown when click dropdown item', async () => {
const el = await fixture<typeOfBlDropdown>(html`
<bl-dropdown>
<bl-dropdown-item>dropdown-item</bl-dropdown-item>
</bl-dropdown>
`);

const buttonHost = <BlButton>el.shadowRoot?.querySelector('bl-button');
const button = buttonHost.shadowRoot?.querySelector('.button') as HTMLElement | null;
const popover = <BlPopover>el.shadowRoot?.querySelector('bl-popover');

button?.click();
expect(el.opened).to.true;
expect(popover.visible).to.true;

const item = el
.querySelector('bl-dropdown-item')
?.shadowRoot?.querySelector('bl-button') as HTMLElement | null;
item?.click();

setTimeout(() => {
expect(el.opened).to.false;
expect(popover.visible).to.false;
});
});

it('should fire event when dropdown opened', async () => {
const el = await fixture<typeOfBlDropdown>(html`<bl-dropdown></bl-dropdown>`);

Expand Down
1 change: 1 addition & 0 deletions src/components/dropdown/item/bl-dropdown-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export default class BlDropdownItem extends LitElement {
@event('bl-dropdown-item-click') private onClick: EventDispatcher<string>;

private _handleClick() {
this.BlDropdownField?.close();
this.onClick('Action clicked!');
}

Expand Down

0 comments on commit f78477b

Please sign in to comment.