Skip to content
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

Add aria-label to icon only menu button stories #1541

Merged
merged 4 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/unlucky-adults-push.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sl-design-system/menu': patch
---

Add label property to menu button, which set's the aria-label on the button
12 changes: 12 additions & 0 deletions packages/components/menu/src/menu-button.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ describe('sl-menu-button', () => {
expect(button).to.exist;
});

it('should not have a label', () => {
expect(el.label).to.be.undefined;
expect(button).not.to.have.attribute('aria-label');
});

it('should have an label when set', async () => {
el.label = 'Label';
await el.updateComplete;

expect(button).to.have.attribute('aria-label', 'Label');
});

it('should not have a disabled button', () => {
expect(button).not.to.have.attribute('disabled');
expect(button.disabled).not.to.be.true;
Expand Down
8 changes: 5 additions & 3 deletions packages/components/menu/src/menu-button.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { styleMap } from 'lit/directives/style-map.js';
import '../register.js';
import { type MenuButton } from './menu-button.js';

type Props = Pick<MenuButton, 'disabled' | 'fill' | 'position' | 'size' | 'variant'> & {
type Props = Pick<MenuButton, 'disabled' | 'fill' | 'label' | 'position' | 'size' | 'variant'> & {
alignSelf: string;
body: string | TemplateResult;
justifySelf: string;
Expand All @@ -35,7 +35,8 @@ export default {
alignSelf: 'center',
body: 'Button',
disabled: false,
justifySelf: 'center'
justifySelf: 'center',
label: 'Label'
},
argTypes: {
alignSelf: {
Expand Down Expand Up @@ -86,7 +87,7 @@ export default {
// Disables Chromatic's snapshotting on a story level
chromatic: { disableSnapshot: true }
},
render: ({ alignSelf, body, disabled, fill, justifySelf, menuItems, position, size, variant }) => {
render: ({ alignSelf, body, disabled, fill, justifySelf, label, menuItems, position, size, variant }) => {
return html`
<style>
#root-inner {
Expand All @@ -98,6 +99,7 @@ export default {
<sl-menu-button
?disabled=${disabled}
fill=${ifDefined(fill)}
label=${ifDefined(label)}
position=${ifDefined(position)}
size=${ifDefined(size)}
style=${styleMap({ alignSelf, justifySelf })}
Expand Down
4 changes: 4 additions & 0 deletions packages/components/menu/src/menu-button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ export class MenuButton extends ScopedElementsMixin(LitElement) {
/** The fill of the button. */
@property() fill: ButtonFill = 'outline';

/** If the menu button is icon only, use this to set the `aria-label` on the button. */
@property() label?: string;
jpzwarte marked this conversation as resolved.
Show resolved Hide resolved

/** @internal The menu. */
@query('sl-menu') menu!: Menu;

Expand Down Expand Up @@ -80,6 +83,7 @@ export class MenuButton extends ScopedElementsMixin(LitElement) {
@click=${this.#onClick}
@keydown=${this.#onKeydown}
?disabled=${this.disabled}
aria-label=${ifDefined(this.label)}
fill=${ifDefined(this.fill)}
part="button"
size=${ifDefined(this.size)}
Expand Down