-
Notifications
You must be signed in to change notification settings - Fork 205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(dropdown): improve accessibility #905
Changes from all commits
068b3b3
82fd8ea
94b8180
2f25390
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,8 @@ import { | |
property, | ||
CSSResultArray, | ||
TemplateResult, | ||
PropertyValues, | ||
ifDefined, | ||
} from '@spectrum-web-components/base'; | ||
|
||
import '@spectrum-web-components/icon/sp-icon.js'; | ||
|
@@ -37,8 +39,13 @@ export class MenuItem extends ActionButton { | |
return [menuItemStyles, checkmarkMediumStyles]; | ||
} | ||
|
||
static instanceCount = 0; | ||
|
||
private _value = ''; | ||
|
||
@property({ type: Boolean, reflect: true }) | ||
public focused = false; | ||
|
||
@property({ type: String }) | ||
public get value(): string { | ||
return this._value || this.itemText; | ||
|
@@ -83,6 +90,31 @@ export class MenuItem extends ActionButton { | |
return content; | ||
} | ||
|
||
protected renderButton(): TemplateResult { | ||
return html` | ||
<div id="button" class="button" aria-label=${ifDefined(this.label)}> | ||
${this.buttonContent} | ||
</div> | ||
`; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hadn't realized this extended from ActionButton -- neat. Whenever something like a core render method is overridden I try to think about maintainability. Since the only difference is the tag name, is that something you could parameterize? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could make the source render method more composable so that we only have to override part of it:
That's probably nicer system wide, I'll take swing at it. |
||
|
||
protected firstUpdated(changes: PropertyValues): void { | ||
super.firstUpdated(changes); | ||
if (!this.hasAttribute('id')) { | ||
this.id = `sp-menu-item-${MenuItem.instanceCount++}`; | ||
} | ||
} | ||
|
||
protected updated(changes: PropertyValues): void { | ||
super.updated(changes); | ||
if (this.getAttribute('role') === 'option' && changes.has('selected')) { | ||
this.setAttribute( | ||
'aria-selected', | ||
this.selected ? 'true' : 'false' | ||
); | ||
} | ||
} | ||
|
||
public connectedCallback(): void { | ||
super.connectedCallback(); | ||
if (!this.hasAttribute('role')) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you need this change -- is this just a code style choice, or is there something subtle I'm missing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just style, I had removed this check at one point and then re-added it not knowing the style changed. There may be some slight amount of type security outside of the TS space in the small fraction of time
this.menuItems === undefined
, but I don't know enough V8/timing to confirm.