remove aria- and role attribs from slots; closes #1422

This commit is contained in:
Cory LaViska
2023-07-11 15:00:56 -04:00
parent 969aad6f7e
commit 1011326840
19 changed files with 144 additions and 128 deletions

View File

@@ -18,6 +18,8 @@ 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]
- Updated ESLint and related plugins to the latest versions
## 2.5.2

View File

@@ -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`

View File

@@ -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>
`;
}

View File

@@ -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', () => {

View File

@@ -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>
`;
}
}

View File

@@ -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>
`;
}

View File

@@ -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>
`;
}
}

View File

@@ -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>
`;
}
}

View File

@@ -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>
`;

View File

@@ -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);
}

View File

@@ -447,7 +447,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"
@@ -482,64 +485,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>
`;

View File

@@ -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 */

View File

@@ -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>
`;
}

View File

@@ -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>
`;
}

View File

@@ -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>

View File

@@ -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>
`;
}

View File

@@ -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>
`;
}

View File

@@ -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>
`;
}

View File

@@ -409,8 +409,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>
`;
}