You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Added visually hidden default slot rendering to sp-close-button so text content is accessible to screen readers while remaining invisible to sighted users.
Copy file name to clipboardExpand all lines: 1st-gen/packages/button/clear-button.md
+17-29Lines changed: 17 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,34 +25,21 @@ import { ClearButton } from '@spectrum-web-components/button';
25
25
26
26
### Anatomy
27
27
28
-
The clear button is a button with only close icon.
28
+
The clear button is a button with only a close icon.
29
29
30
30
```html
31
-
<sp-clear-button>Reset</sp-clear-button>
31
+
<sp-clear-buttonlabel="Reset"></sp-clear-button>
32
32
```
33
33
34
34
#### Label
35
35
36
-
The label for an `<sp-clear-button>` element can be set via it's default slot or with the `label` attribute. With either method, the label will not be visible but still read by screen readers.
37
-
38
-
<sp-tabsselected="attribute"autolabel="Labelling a button">
39
-
<sp-tabvalue="slot">Default slot</sp-tab>
40
-
<sp-tab-panelvalue="slot">
41
-
42
-
```html demo
43
-
<sp-clear-button>Clear</sp-clear-button>
44
-
```
45
-
46
-
</sp-tab-panel>
47
-
<sp-tabvalue="attribute">Label attribute</sp-tab>
48
-
<sp-tab-panelvalue="attribute">
36
+
An accessible label for an `<sp-clear-button>` must be provided using the `label` attribute. This sets the `aria-label` for screen readers. Unlike other button types, the clear button only displays an icon and does not render slot content, so the `label` attribute is the only way to provide an accessible name.
A button is required to have either text in the default slot or a `label` attribute on the `<sp-clear-button>`.
148
+
A button is required to have a `label` attribute on the `<sp-clear-button>` to provide an accessible name for screen readers. The `label` attribute sets the `aria-label` property, ensuring the button is properly announced to assistive technologies.
* An accessible label that describes the component.
69
+
* It will be applied to aria-label, but not visually rendered.
70
+
* This attribute is required for clear buttons.
71
+
*/
72
+
@property()
73
+
publicoverridelabel!: string;
74
+
67
75
@property({type: Boolean,reflect: true})
68
76
publicquiet=false;
69
77
@@ -121,4 +129,28 @@ export class ClearButton extends SizedMixin(StyledButton, {
121
129
<divclass="fill">${super.render()}</div>
122
130
`;
123
131
}
132
+
133
+
publicoverrideconnectedCallback(): void{
134
+
super.connectedCallback();
135
+
136
+
// Deprecation warning for default slot when content is provided
137
+
if(window.__swc.DEBUG&&this.textContent?.trim()){
138
+
window.__swc.warn(
139
+
this,
140
+
`The default slot for text content in <${this.localName}> has been deprecated and will be removed in a future release. The clear button is icon-only and does not render slot content. Use the "label" attribute instead to provide an accessible name.`,
`The "label" attribute is required on <${this.localName}> to provide an accessible name for screen readers. Please add a label attribute, e.g., <${this.localName} label="Clear">.`,
0 commit comments