Skip to content

Commit

Permalink
fixing menu and button IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
SBBlee committed Aug 12, 2024
1 parent 6cbefbf commit edbf154
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
37 changes: 23 additions & 14 deletions src/components/molecules/Dropdown/Dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,14 @@ export default class Dropdown extends HTMLElement {
this.querySelector(
'cod-button[data-bs-toggle="dropdown"]',
).addEventListener('click', this._onClick);
this.querySelector(
'cod-button[data-bs-toggle="dropdown"]')
.setAttribute('aria-controls', '#dropdown-id');
const buttonElt = this.querySelector(
'cod-button[data-bs-toggle="dropdown"]',
);
const menuId = this.querySelector('cod-dropdown-menu')
.getAttribute('id');
buttonElt
.setAttribute('aria-controls', menuId);

}
if (!this.shadowRoot.querySelector('div')) {
this.shadowRoot.appendChild(this.dropdown);
Expand All @@ -68,23 +73,27 @@ export default class Dropdown extends HTMLElement {
if (e.target.getAttribute('data-bs-toggle') === 'dropdown') {
if (this.getAttribute('aria-expanded') === 'true') {
this.setAttribute('aria-expanded', 'false');
this.parentElement
.querySelector('cod-dropdown-menu')
const dropdownMenu = this.parentElement
.querySelector('cod-dropdown-menu');
dropdownMenu
.setAttribute('data-show', 'false');
this.parentElement
.querySelector('cod-dropdown-menu')
dropdownMenu
.setAttribute('aria-hidden', 'true');
} else {
this.setAttribute('aria-expanded', 'true');
this.parentElement
.querySelector('cod-dropdown-menu')
const dropdownMenu = this.parentElement
.querySelector('cod-dropdown-menu');
dropdownMenu
.setAttribute('data-show', 'true');
dropdownMenu
.setAttribute('aria-hidden', 'false');

const buttonId = this.parentElement
.querySelector('cod-button')
.getAttribute('id');
this.parentElement
.querySelector('cod-dropdown-menu')
.setAttribute('aria-labelledby', '#button-id');
this.parentElement
.querySelector('cod-dropdown-menu')
.setAttribute('aria-hidden', 'false');
.querySelector('cod-dropdown-menu')
.setAttribute('aria-labelledby', buttonId);
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/stories/dropdown.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const Basic = () => html`
>
Dropdown button
</button>
<ul class="dropdown-menu" id="dropdown-menu">
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#">Action</a></li>
<li><a class="dropdown-item" href="#">Another action</a></li>
<li>
Expand All @@ -27,6 +27,7 @@ export const Basic = () => html`
</ul>
</div>
<cod-button
id="dropdownControl"
data-label="Dropdown button"
data-background-color="primary"
data-primary="true"
Expand All @@ -36,7 +37,7 @@ export const Basic = () => html`
aria-expanded="false"
data-extra-classes="dropdown-toggle"
></cod-button>
<cod-dropdown-menu>
<cod-dropdown-menu id="dropdownMenu">
<li><a class="dropdown-item" href="#">Action</a></li>
<li><a class="dropdown-item" href="#">Another action</a></li>
<li><a class="dropdown-item" href="#">Something else here</a></li>
Expand Down

0 comments on commit edbf154

Please sign in to comment.