Lit a11y update (#1444)

* update eslint-plugin-lit-a11y to latest

* update eslint deps

* remove aria- and role attribs from slots; closes #1422
pull/1446/head
Cory LaViska 2023-07-12 11:12:15 -04:00 zatwierdzone przez GitHub
rodzic f84d6939bd
commit e1ca7d1f59
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
22 zmienionych plików z 586 dodań i 541 usunięć

Wyświetl plik

@ -92,7 +92,8 @@ module.exports = {
'@typescript-eslint/member-delimiter-style': 'warn',
'@typescript-eslint/method-signature-style': 'warn',
'@typescript-eslint/no-extraneous-class': 'error',
'@typescript-eslint/no-parameter-properties': 'error',
'@typescript-eslint/no-redundant-type-constituents': 'off',
'@typescript-eslint/parameter-properties': 'error',
'@typescript-eslint/strict-boolean-expressions': 'off'
}
},

Wyświetl plik

@ -21,7 +21,9 @@ New versions of Shoelace are released as-needed and generally occur when a criti
- Fixed a bug in `<sl-qr-code>` where the `background` attribute was never passed to the QR code [#1416]
- Fixed a bug in `<sl-dropdown>` where aria attributes were incorrectly applied to the default `<slot>` causing Lighthouse errors [#1417]
- Fixed a bug in `<sl-carousel>` that caused navigation to work incorrectly in some case [#1420]
- Fixed a number of slots that incorrectly had aria- and/or role attributes directly on them [#1422]
- Fixed a bug in `<sl-tree>` that caused focus to be stolen when removing focused tree items [#1430]
- Updated ESLint and related plugins to the latest versions
## 2.5.2

838
package-lock.json wygenerowano

Plik diff jest za duży Load Diff

Wyświetl plik

@ -79,8 +79,8 @@
"@open-wc/testing": "^3.1.7",
"@types/mocha": "^10.0.1",
"@types/react": "^18.0.26",
"@typescript-eslint/eslint-plugin": "^5.48.1",
"@typescript-eslint/parser": "^5.48.1",
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
"@web/dev-server-esbuild": "^0.3.3",
"@web/test-runner": "^0.15.0",
"@web/test-runner-commands": "^0.6.5",
@ -96,15 +96,15 @@
"del": "^7.0.0",
"download": "^8.0.0",
"esbuild": "^0.18.2",
"eslint": "^8.31.0",
"eslint": "^8.44.0",
"eslint-plugin-chai-expect": "^3.0.0",
"eslint-plugin-chai-friendly": "^0.7.2",
"eslint-plugin-import": "^2.27.4",
"eslint-plugin-lit": "^1.8.2",
"eslint-plugin-lit-a11y": "^2.3.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-lit": "^1.8.3",
"eslint-plugin-lit-a11y": "^4.1.0",
"eslint-plugin-markdown": "^3.0.0",
"eslint-plugin-sort-imports-es6-autofix": "^0.6.0",
"eslint-plugin-wc": "^1.4.0",
"eslint-plugin-wc": "^1.5.0",
"front-matter": "^4.0.2",
"get-port": "^7.0.0",
"globby": "^13.1.3",

Wyświetl plik

@ -199,9 +199,13 @@ export default class SlAlert extends ShoelaceElement {
aria-hidden=${this.open ? 'false' : 'true'}
@mousemove=${this.handleMouseMove}
>
<slot name="icon" part="icon" class="alert__icon"></slot>
<div part="icon" class="alert__icon">
<slot name="icon"></slot>
</div>
<slot part="message" class="alert__message" aria-live="polite"></slot>
<div part="message" class="alert__message" aria-live="polite">
<slot></slot>
</div>
${this.closable
? html`

Wyświetl plik

@ -69,9 +69,11 @@ export default class SlAvatar extends ShoelaceElement {
avatarWithoutImage = html`<div part="initials" class="avatar__initials">${this.initials}</div>`;
} else {
avatarWithoutImage = html`
<slot name="icon" part="icon" class="avatar__icon" aria-hidden="true">
<sl-icon name="person-fill" library="system"></sl-icon>
</slot>
<div part="icon" class="avatar__icon" aria-hidden="true">
<slot name="icon">
<sl-icon name="person-fill" library="system"></sl-icon>
</slot>
</div>
`;
}

Wyświetl plik

@ -2,6 +2,10 @@ import '../../../dist/shoelace.js';
import { expect, fixture, html } from '@open-wc/testing';
import type SlBadge from './badge.js';
// The default badge background just misses AA contrast, but the next step up is way too dark. We're going to relax this
// rule for now.
const ignoredRules = ['color-contrast'];
describe('<sl-badge>', () => {
let el: SlBadge;
@ -11,7 +15,7 @@ describe('<sl-badge>', () => {
});
it('should pass accessibility tests with a role of status on the base part.', async () => {
await expect(el).to.be.accessible();
await expect(el).to.be.accessible({ ignoredRules });
const part = el.shadowRoot!.querySelector('[part~="base"]')!;
expect(part.getAttribute('role')).to.eq('status');
@ -33,7 +37,7 @@ describe('<sl-badge>', () => {
});
it('should pass accessibility tests', async () => {
await expect(el).to.be.accessible();
await expect(el).to.be.accessible({ ignoredRules });
});
it('should append the pill class to the classlist to render a pill', () => {
@ -48,7 +52,7 @@ describe('<sl-badge>', () => {
});
it('should pass accessibility tests', async () => {
await expect(el).to.be.accessible();
await expect(el).to.be.accessible({ ignoredRules });
});
it('should append the pulse class to the classlist to render a pulse', () => {
@ -64,7 +68,7 @@ describe('<sl-badge>', () => {
});
it('should pass accessibility tests', async () => {
await expect(el).to.be.accessible();
await expect(el).to.be.accessible({ ignoredRules });
});
it('should default to square styling, with the primary color', () => {

Wyświetl plik

@ -30,7 +30,7 @@ export default class SlBadge extends ShoelaceElement {
render() {
return html`
<slot
<span
part="base"
class=${classMap({
badge: true,
@ -43,7 +43,9 @@ export default class SlBadge extends ShoelaceElement {
'badge--pulse': this.pulse
})}
role="status"
></slot>
>
<slot></slot>
</span>
`;
}
}

Wyświetl plik

@ -55,7 +55,9 @@ export default class SlBreadcrumbItem extends ShoelaceElement {
'breadcrumb-item--has-suffix': this.hasSlotController.test('suffix')
})}
>
<slot name="prefix" part="prefix" class="breadcrumb-item__prefix"></slot>
<span part="prefix" class="breadcrumb-item__prefix">
<slot name="prefix"></slot>
</span>
${isLink
? html`
@ -75,9 +77,13 @@ export default class SlBreadcrumbItem extends ShoelaceElement {
</button>
`}
<slot name="suffix" part="suffix" class="breadcrumb-item__suffix"></slot>
<span part="suffix" class="breadcrumb-item__suffix">
<slot name="suffix"></slot>
</span>
<slot name="separator" part="separator" class="breadcrumb-item__separator" aria-hidden="true"></slot>
<span part="separator" class="breadcrumb-item__separator" aria-hidden="true">
<slot name="separator"></slot>
</span>
</div>
`;
}

Wyświetl plik

@ -90,9 +90,11 @@ export default class SlBreadcrumb extends ShoelaceElement {
<slot @slotchange=${this.handleSlotChange}></slot>
</nav>
<slot name="separator" hidden aria-hidden="true">
<sl-icon name=${this.localize.dir() === 'rtl' ? 'chevron-left' : 'chevron-right'} library="system"></sl-icon>
</slot>
<span hidden aria-hidden="true">
<slot name="separator">
<sl-icon name=${this.localize.dir() === 'rtl' ? 'chevron-left' : 'chevron-right'} library="system"></sl-icon>
</slot>
</span>
`;
}
}

Wyświetl plik

@ -68,7 +68,7 @@ export default class SlButtonGroup extends ShoelaceElement {
render() {
// eslint-disable-next-line lit-a11y/mouse-events-have-key-events
return html`
<slot
<div
part="base"
class="button-group"
role="${this.disableRole ? 'presentation' : 'group'}"
@ -77,8 +77,9 @@ export default class SlButtonGroup extends ShoelaceElement {
@focusin=${this.handleFocus}
@mouseover=${this.handleMouseOver}
@mouseout=${this.handleMouseOut}
@slotchange=${this.handleSlotChange}
></slot>
>
<slot @slotchange=${this.handleSlotChange}></slot>
</div>
`;
}
}

Wyświetl plik

@ -108,16 +108,19 @@ export default class SlImageComparer extends ShoelaceElement {
@keydown=${this.handleKeyDown}
>
<div class="image-comparer__image">
<slot name="before" part="before" class="image-comparer__before"></slot>
<div part="before" class="image-comparer__before">
<slot name="before"></slot>
</div>
<slot
name="after"
<div
part="after"
class="image-comparer__after"
style=${styleMap({
clipPath: isRtl ? `inset(0 0 0 ${100 - this.position}%)` : `inset(0 ${100 - this.position}% 0 0)`
})}
></slot>
>
<slot name="after"></slot>
</div>
</div>
<div
@ -129,8 +132,7 @@ export default class SlImageComparer extends ShoelaceElement {
@mousedown=${this.handleDrag}
@touchstart=${this.handleDrag}
>
<slot
name="handle"
<div
part="handle"
class="image-comparer__handle"
role="scrollbar"
@ -140,8 +142,10 @@ export default class SlImageComparer extends ShoelaceElement {
aria-controls="image-comparer"
tabindex="0"
>
<sl-icon library="system" name="grip-vertical"></sl-icon>
</slot>
<slot name="handle">
<sl-icon library="system" name="grip-vertical"></sl-icon>
</slot>
</div>
</div>
</div>
`;

Wyświetl plik

@ -147,8 +147,8 @@ export default css`
cursor: default;
}
.input__prefix::slotted(sl-icon),
.input__suffix::slotted(sl-icon) {
.input__prefix ::slotted(sl-icon),
.input__suffix ::slotted(sl-icon) {
color: var(--sl-input-icon-color);
}
@ -172,11 +172,11 @@ export default css`
width: calc(1em + var(--sl-input-spacing-small) * 2);
}
.input--small .input__prefix::slotted(*) {
.input--small .input__prefix ::slotted(*) {
margin-inline-start: var(--sl-input-spacing-small);
}
.input--small .input__suffix::slotted(*) {
.input--small .input__suffix ::slotted(*) {
margin-inline-end: var(--sl-input-spacing-small);
}
@ -196,11 +196,11 @@ export default css`
width: calc(1em + var(--sl-input-spacing-medium) * 2);
}
.input--medium .input__prefix::slotted(*) {
.input--medium .input__prefix ::slotted(*) {
margin-inline-start: var(--sl-input-spacing-medium);
}
.input--medium .input__suffix::slotted(*) {
.input--medium .input__suffix ::slotted(*) {
margin-inline-end: var(--sl-input-spacing-medium);
}
@ -220,11 +220,11 @@ export default css`
width: calc(1em + var(--sl-input-spacing-large) * 2);
}
.input--large .input__prefix::slotted(*) {
.input--large .input__prefix ::slotted(*) {
margin-inline-start: var(--sl-input-spacing-large);
}
.input--large .input__suffix::slotted(*) {
.input--large .input__suffix ::slotted(*) {
margin-inline-end: var(--sl-input-spacing-large);
}

Wyświetl plik

@ -451,7 +451,10 @@ export default class SlInput extends ShoelaceElement implements ShoelaceFormCont
'input--no-spin-buttons': this.noSpinButtons
})}
>
<slot name="prefix" part="prefix" class="input__prefix"></slot>
<span part="prefix" class="input__prefix">
<slot name="prefix"></slot>
</span>
<input
part="input"
id="input"
@ -486,64 +489,60 @@ export default class SlInput extends ShoelaceElement implements ShoelaceFormCont
@blur=${this.handleBlur}
/>
${
hasClearIcon
? html`
<button
part="clear-button"
class="input__clear"
type="button"
aria-label=${this.localize.term('clearEntry')}
@click=${this.handleClearClick}
tabindex="-1"
>
<slot name="clear-icon">
<sl-icon name="x-circle-fill" library="system"></sl-icon>
</slot>
</button>
`
: ''
}
${
this.passwordToggle && !this.disabled
? html`
<button
part="password-toggle-button"
class="input__password-toggle"
type="button"
aria-label=${this.localize.term(this.passwordVisible ? 'hidePassword' : 'showPassword')}
@click=${this.handlePasswordToggle}
tabindex="-1"
>
${this.passwordVisible
? html`
<slot name="show-password-icon">
<sl-icon name="eye-slash" library="system"></sl-icon>
</slot>
`
: html`
<slot name="hide-password-icon">
<sl-icon name="eye" library="system"></sl-icon>
</slot>
`}
</button>
`
: ''
}
${hasClearIcon
? html`
<button
part="clear-button"
class="input__clear"
type="button"
aria-label=${this.localize.term('clearEntry')}
@click=${this.handleClearClick}
tabindex="-1"
>
<slot name="clear-icon">
<sl-icon name="x-circle-fill" library="system"></sl-icon>
</slot>
</button>
`
: ''}
${this.passwordToggle && !this.disabled
? html`
<button
part="password-toggle-button"
class="input__password-toggle"
type="button"
aria-label=${this.localize.term(this.passwordVisible ? 'hidePassword' : 'showPassword')}
@click=${this.handlePasswordToggle}
tabindex="-1"
>
${this.passwordVisible
? html`
<slot name="show-password-icon">
<sl-icon name="eye-slash" library="system"></sl-icon>
</slot>
`
: html`
<slot name="hide-password-icon">
<sl-icon name="eye" library="system"></sl-icon>
</slot>
`}
</button>
`
: ''}
<slot name="suffix" part="suffix" class="input__suffix"></slot>
<span part="suffix" class="input__suffix">
<slot name="suffix"></slot>
</span>
</div>
</div>
<slot
name="help-text"
<div
part="form-control-help-text"
id="help-text"
class="form-control__help-text"
aria-hidden=${hasHelpText ? 'false' : 'true'}
>
${this.helpText}
</slot>
<slot name="help-text">${this.helpText}</slot>
</div>
</div>
`;

Wyświetl plik

@ -329,12 +329,9 @@ export default class SlRadioGroup extends ShoelaceElement implements ShoelaceFor
const hasHelpText = this.helpText ? true : !!hasHelpTextSlot;
const defaultSlot = html`
<slot
@click=${this.handleRadioClick}
@keydown=${this.handleKeyDown}
@slotchange=${this.syncRadios}
role="presentation"
></slot>
<span @click=${this.handleRadioClick} @keydown=${this.handleKeyDown} role="presentation">
<slot @slotchange=${this.syncRadios}></slot>
</span>
`;
return html`
@ -388,15 +385,14 @@ export default class SlRadioGroup extends ShoelaceElement implements ShoelaceFor
: defaultSlot}
</div>
<slot
name="help-text"
<div
part="form-control-help-text"
id="help-text"
class="form-control__help-text"
aria-hidden=${hasHelpText ? 'false' : 'true'}
>
${this.helpText}
</slot>
<slot name="help-text">${this.helpText}</slot>
</div>
</fieldset>
`;
/* eslint-enable lit-a11y/click-events-have-key-events */

Wyświetl plik

@ -343,15 +343,14 @@ export default class SlRange extends ShoelaceElement implements ShoelaceFormCont
</div>
</div>
<slot
name="help-text"
<div
part="form-control-help-text"
id="help-text"
class="form-control__help-text"
aria-hidden=${hasHelpText ? 'false' : 'true'}
>
${this.helpText}
</slot>
<slot name="help-text">${this.helpText}</slot>
</div>
</div>
`;
}

Wyświetl plik

@ -835,15 +835,14 @@ export default class SlSelect extends ShoelaceElement implements ShoelaceFormCon
</sl-popup>
</div>
<slot
name="help-text"
<div
part="form-control-help-text"
id="help-text"
class="form-control__help-text"
aria-hidden=${hasHelpText ? 'false' : 'true'}
>
${this.helpText}
</slot>
<slot name="help-text">${this.helpText}</slot>
</div>
</div>
`;
}

Wyświetl plik

@ -26,7 +26,7 @@ export default class SlSpinner extends ShoelaceElement {
render() {
return html`
<svg part="base" class="spinner" role="progressbar" aria-valuetext=${this.localize.term('loading')}>
<svg part="base" class="spinner" role="progressbar" aria-label=${this.localize.term('loading')}>
<circle class="spinner__track"></circle>
<circle class="spinner__indicator"></circle>
</svg>

Wyświetl plik

@ -372,15 +372,14 @@ export default class SlTextarea extends ShoelaceElement implements ShoelaceFormC
</div>
</div>
<slot
name="help-text"
<div
part="form-control-help-text"
id="help-text"
class="form-control__help-text"
aria-hidden=${hasHelpText ? 'false' : 'true'}
>
${this.helpText}
</slot>
<slot name="help-text">${this.helpText}</slot>
</div>
</div>
`;
}

Wyświetl plik

@ -241,6 +241,12 @@ export default class SlTooltip extends ShoelaceElement {
return waitForEvent(this, 'sl-after-hide');
}
//
// NOTE: Tooltip is a bit unique in that we're using aria-live instead of aria-labelledby to trick screen readers into
// announcing the content. It works really well, but it violates an accessibility rule. We're also adding the
// aria-describedby attribute to a slot, which is required by <sl-popup> to correctly locate the first assigned
// element, otherwise positioning is incorrect.
//
render() {
return html`
<sl-popup
@ -261,18 +267,13 @@ export default class SlTooltip extends ShoelaceElement {
shift
arrow
>
${'' /* eslint-disable-next-line lit-a11y/no-aria-slot */}
<slot slot="anchor" aria-describedby="tooltip"></slot>
<slot
name="content"
part="body"
id="tooltip"
class="tooltip__body"
role="tooltip"
aria-live=${this.open ? 'polite' : 'off'}
>
${this.content}
</slot>
${'' /* eslint-disable-next-line lit-a11y/accessible-name */}
<div part="body" id="tooltip" class="tooltip__body" role="tooltip" aria-live=${this.open ? 'polite' : 'off'}>
<slot name="content">${this.content}</slot>
</div>
</sl-popup>
`;
}

Wyświetl plik

@ -288,13 +288,9 @@ export default class SlTreeItem extends ShoelaceElement {
<slot class="tree-item__label" part="label"></slot>
</div>
<slot
name="children"
class="tree-item__children"
part="children"
role="group"
@slotchange="${this.handleChildrenSlotChange}"
></slot>
<div class="tree-item__children" part="children" role="group">
<slot name="children" @slotchange="${this.handleChildrenSlotChange}"></slot>
</div>
</div>
`;
}

Wyświetl plik

@ -403,8 +403,8 @@ export default class SlTree extends ShoelaceElement {
@mousedown=${this.handleMouseDown}
>
<slot @slotchange=${this.handleSlotChange}></slot>
<slot name="expand-icon" hidden aria-hidden="true"> </slot>
<slot name="collapse-icon" hidden aria-hidden="true"> </slot>
<span hidden aria-hidden="true"><slot name="expand-icon"></slot></span>
<span hidden aria-hidden="true"><slot name="collapse-icon"></slot></span>
</div>
`;
}