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(number-field): update button label to use number-field-labels as part of the text #3474

Merged
merged 5 commits into from
Jul 21, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 8 additions & 2 deletions packages/number-field/src/NumberField.ts
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,10 @@ export class NumberField extends TextfieldBase {
return this.focused ? this._numberParserFocused : this._numberParser;
}

applyFocusElementLabel = (value?: string): void => {
this.appliedLabel = value;
};

private _numberParser?: NumberParser;
private _numberParserFocused?: NumberParser;

Expand Down Expand Up @@ -587,7 +591,8 @@ export class NumberField extends TextfieldBase {
>
<sp-action-button
class="step-up"
label="Increment"
aria-describedby=${this.helpTextId}
label=${'Increase ' + this.appliedLabel}
tabindex="-1"
?focused=${this.focused}
?disabled=${this.disabled ||
Expand All @@ -600,7 +605,8 @@ export class NumberField extends TextfieldBase {
</sp-action-button>
<sp-action-button
class="step-down"
label="Decrement"
aria-describedby=${this.helpTextId}
label=${'Decrease ' + this.appliedLabel}
tabindex="-1"
?focused=${this.focused}
?disabled=${this.disabled ||
Expand Down
44 changes: 43 additions & 1 deletion packages/number-field/test/number-field.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
aTimeout,
elementUpdated,
expect,
fixture,
nextFrame,
oneEvent,
} from '@open-wc/testing';
Expand All @@ -36,7 +37,12 @@ import {
indeterminatePlaceholder,
NumberField,
} from '@spectrum-web-components/number-field';
import { sendKeys, setUserAgent } from '@web/test-runner-commands';
import {
a11ySnapshot,
findAccessibilityNode,
sendKeys,
setUserAgent,
} from '@web/test-runner-commands';
import { spy } from 'sinon';
import { clickBySelector, getElFrom } from './helpers.js';
import { createLanguageContext } from '../../../tools/reactive-controllers/test/helpers.js';
Expand Down Expand Up @@ -1260,4 +1266,40 @@ describe('NumberField', () => {
await clickBySelector(el, '.step-down');
});
});
describe('accessibility model', () => {
it('buttons have proper label', async () => {
await fixture<HTMLDivElement>(html`
<div>
${Default({
onChange: () => {
return;
},
})}
</div>
`);

type NamedNode = { name: string };
const snapshot = (await a11ySnapshot(
{}
)) as unknown as NamedNode & {
children: NamedNode[];
};

expect(
findAccessibilityNode<NamedNode>(
snapshot,
(node) => node.name === 'Increase Enter a number'
),
'`name` is the label text'
).to.not.be.null;

expect(
findAccessibilityNode<NamedNode>(
snapshot,
(node) => node.name === 'Decrease Enter a number'
),
'`name` is the label text'
).to.not.be.null;
});
});
});
11 changes: 9 additions & 2 deletions packages/textfield/src/Textfield.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ export class TextfieldBase extends ManageHelpText(
return [textfieldStyles, checkmarkStyles];
}

@state()
appliedLabel?: string;

@property({ attribute: 'allowed-keys' })
allowedKeys = '';

Expand Down Expand Up @@ -235,7 +238,9 @@ export class TextfieldBase extends ManageHelpText(
<!-- @ts-ignore -->
<textarea
aria-describedby=${this.helpTextId}
aria-label=${this.label || this.placeholder}
aria-label=${this.label ||
this.appliedLabel ||
this.placeholder}
aria-invalid=${ifDefined(this.invalid || undefined)}
class="input"
maxlength=${ifDefined(
Expand Down Expand Up @@ -266,7 +271,9 @@ export class TextfieldBase extends ManageHelpText(
<input
type=${this.type}
aria-describedby=${this.helpTextId}
aria-label=${this.label || this.placeholder}
aria-label=${this.label ||
this.appliedLabel ||
this.placeholder}
aria-invalid=${ifDefined(this.invalid || undefined)}
class="input"
maxlength=${ifDefined(
Expand Down