Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 567226b

Browse files
committed
Set roles if non has been set
- Setting role=menu only if one doesn't exsit already - Setting role=button on summary to perform as a menu button
1 parent a023e4d commit 567226b

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,16 @@ class DetailsMenuElement extends HTMLElement {
2626
}
2727

2828
connectedCallback() {
29-
this.setAttribute('role', 'menu')
29+
if (!this.hasAttribute('role')) this.setAttribute('role', 'menu')
3030

3131
const details = this.parentElement
3232
if (!details) return
3333

3434
const summary = details.querySelector('summary')
35-
if (summary) summary.setAttribute('aria-haspopup', 'menu')
35+
if (summary) {
36+
summary.setAttribute('aria-haspopup', 'menu')
37+
if (!summary.hasAttribute('role')) summary.setAttribute('role', 'button')
38+
}
3639

3740
details.addEventListener('click', shouldCommit)
3841
details.addEventListener('change', shouldCommit)

0 commit comments

Comments
 (0)