Skip to content
This repository was archived by the owner on Mar 7, 2025. It is now read-only.

Commit

Permalink
feat(disableEventShow): add attribute to only display bib with show m…
Browse files Browse the repository at this point in the history
…ethod #109 #110
  • Loading branch information
jason-capsule42 committed Mar 28, 2022
1 parent a5ae303 commit 8ad22bc
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 9 deletions.
6 changes: 6 additions & 0 deletions demo/apiExamples.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

# auro-dropdown

## Attributes

| Attribute | Type | Description |
|--------------------|-------------|--------------------------------------------------|
| [disableEventShow](#disableEventShow) | ` Boolean ` | If declared, the dropdown will only show by calling the API .show() public method. |

## Properties

| Property | Attribute | Type | Default | Description |
Expand Down
6 changes: 6 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# auro-dropdown

## Attributes

| Attribute | Type | Description |
|--------------------|-------------|--------------------------------------------------|
| `disableEventShow` | ` Boolean ` | If declared, the dropdown will only show by calling the API .show() public method. |

## Properties

| Property | Attribute | Type | Default | Description |
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 12 additions & 7 deletions src/auro-dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import Popover from "../lib/popover";
* @attr { Boolean } bordered - If declared, applies a border around the trigger slot.
* @attr { Boolean } chevron - If declared, the dropdown displays an display state chevron on the right.
* @attr { Boolean } disabled - If declared, the dropdown is not interactive.
* @attr { Boolean } disableEventShow - If declared, the dropdown will only show by calling the API .show() public method.
* @attr { Boolean } error - If declared in combination with `bordered` property or `helpText` slot content, will apply red color to both.
* @attr { Boolean } inset - If declared, will apply padding around trigger slot content.
* @attr { Boolean } rounded - If declared, will apply border-radius to trigger and default slots.
Expand Down Expand Up @@ -123,7 +124,7 @@ class AuroDropdown extends LitElement {
focusableElementSelectors.forEach((selector) => {
// check if the trigger root element itself is focusable
if (triggerSlotContentRoot.matches(selector)) {
this.tabIndex = 0;
this.tabIndex = -1;

return;
}
Expand All @@ -138,6 +139,7 @@ class AuroDropdown extends LitElement {

firstUpdated() {
this.fixWidth();
this.setAttribute('aria-expanded', this.isPopoverVisible);

this.trigger = this.shadowRoot.querySelector(`#trigger`);
this.triggerChevron = this.shadowRoot.querySelector(`#showStateIcon`);
Expand Down Expand Up @@ -181,12 +183,14 @@ class AuroDropdown extends LitElement {
}
};

if (this.toggle) {
this.trigger.addEventListener('click', toggleDropdown);
this.trigger.addEventListener('keydown', toggleByKeyboard);
} else {
this.trigger.addEventListener('click', handleShow);
this.trigger.addEventListener('keydown', showByKeyboard);
if (!this.hasAttribute('disableEventShow')) {
if (this.toggle) {
this.trigger.addEventListener('click', toggleDropdown);
this.trigger.addEventListener('keydown', toggleByKeyboard);
} else {
this.trigger.addEventListener('click', handleShow);
this.trigger.addEventListener('keydown', showByKeyboard);
}
}

this.trigger.addEventListener('keydown', hideByKeyboard);
Expand Down Expand Up @@ -276,6 +280,7 @@ class AuroDropdown extends LitElement {

updated(changedProperties) {
if (changedProperties.has('isPopoverVisible')) {
this.setAttribute('aria-expanded', this.isPopoverVisible);
if (this.isPopoverVisible) {
document.addEventListener('click', document.expandedAuroDropdown.outsideClick);
} else if (document.expandedAuroDropdown) {
Expand Down
2 changes: 1 addition & 1 deletion test/auro-dropdown.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe('auro-dropdown', () => {
</auro-dropdown>
`);

await expect (el.shadowRoot.querySelector('#trigger').getAttribute('tabindex')).to.equal('0');
await expect (el.shadowRoot.querySelector('#trigger').getAttribute('tabindex')).to.equal('-1');
})

it('auro-dropdown with focusable trigger child element', async () => {
Expand Down

0 comments on commit 8ad22bc

Please sign in to comment.