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

fix: sp-split-button more button label #3354

Merged
merged 2 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion packages/split-button/src/SplitButton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export class SplitButton extends SizedMixin(PickerBase) {
@click=${this.onButtonClick}
@focus=${this.onButtonFocus}
?disabled=${this.disabled}
aria-label="More"
aria-labelledby="button"
variant=${this.variant}
treatment=${treatment}
size=${this.size}
Expand Down
68 changes: 68 additions & 0 deletions packages/split-button/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { elementUpdated, expect, fixture, oneEvent } from '@open-wc/testing';
import { sendKeys } from '@web/test-runner-commands';
import { html, TemplateResult } from '@spectrum-web-components/base';
import { spy } from 'sinon';
import { a11ySnapshot, findAccessibilityNode } from '@web/test-runner-commands';

import fieldDefaults, {
m as field,
Expand Down Expand Up @@ -97,6 +98,73 @@ export function runSplitButtonTests(
await expect(el1).to.be.accessible();
await expect(el2).to.be.accessible();
});
it('loads splitbutton accessibly and checks labels', async () => {
const test = await fixture<HTMLDivElement>(html`
<div>
<sp-split-button>${deprecatedMenu()}</sp-split-button>
<sp-split-button label="Test" left>
${deprecatedMenu()}
</sp-split-button>
</div>
`);
const el1 = test.querySelector('sp-split-button') as SplitButton;
const el2 = test.querySelector('sp-split-button[left]') as SplitButton;

await elementUpdated(el1);
await elementUpdated(el2);

type NamedRoledPopupNode = {
name: string;
role: string;
haspopup: boolean;
};
const snapshot = (await a11ySnapshot(
{}
)) as unknown as NamedRoledPopupNode & {
children: NamedRoledPopupNode[];
};
expect(
findAccessibilityNode<NamedRoledPopupNode>(
snapshot,
(node) =>
(node.role === 'button' || node.role === 'buttonmenu') &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jnurthen this gets the test passing in Firefox. Not sure if this counts as a bug in Firefox (or possibly in Playwright, they're deprecating these API anyways 😢), but it seems to be OK on our end.

If it's good for you, I'm good to merge this in.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for fixing that. That looks good.

node.name === 'Option 1' &&
node.haspopup
),
'Has a named "button" element with haspopup="true" and name="Option 1"'
).to.not.be.null;
expect(
findAccessibilityNode<NamedRoledPopupNode>(
snapshot,
(node) =>
node.role === 'button' &&
node.name === 'Option 1' &&
!node.haspopup
),
'Has a named "button" element with haspopup="false" and name="Option 1"'
).to.not.be.null;
expect(
findAccessibilityNode<NamedRoledPopupNode>(
snapshot,
(node) =>
(node.role === 'button' || node.role === 'buttonmenu') &&
node.name === 'Test' &&
node.haspopup
),
'Has a named "button" element with haspopup="true" and name="Test"'
).to.not.be.null;
expect(
findAccessibilityNode<NamedRoledPopupNode>(
snapshot,
(node) =>
node.role === 'button' &&
node.name === 'Test' &&
!node.haspopup
),
'Has a named "button" element with haspopup="false" and name="Test"'
).to.not.be.null;
});

it('[type="field"] toggles open/close multiple time', async () => {
const test = await fixture<HTMLDivElement>(
wrapInDiv(
Expand Down