Skip to content

Commit b504a51

Browse files
doc: Add a11y labels to copy/stackblitz buttons on the remaining components (#3417)
Co-authored-by: Maxime Lardenois <maxime.lardenois@orange.com>
1 parent 06d9b6a commit b504a51

16 files changed

Lines changed: 138 additions & 154 deletions

File tree

site/src/components/shortcodes/JsDismiss.astro

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ interface Props {
77
}
88
99
const { name } = Astro.props
10+
const withinButtonLabel = `dismissal button within the ${name}`
11+
const outsideButtonLabel = `dismissal button outside the ${name}`
1012
---
1113

1214
<p>
@@ -15,7 +17,7 @@ const { name } = Astro.props
1517
> as demonstrated below:
1618
</p>
1719

18-
<Code
20+
<Code buttonLabel={withinButtonLabel}
1921
code={`<button class="btn btn-icon btn-minimal" data-bs-dismiss="${name}">\n <svg aria-hidden="true"><use xlink:href="${getVersionedDocsPath('/assets/img/ouds-web-sprite.svg#expurge')}"/></svg>\n <span class="visually-hidden">Close</span>\n</button>`}
2022
lang="html"
2123
/>
@@ -24,7 +26,7 @@ const { name } = Astro.props
2426
or on a button <strong>outside the {name}</strong> using the additional <code>data-bs-target</code> as demonstrated below:
2527
</p>
2628

27-
<Code
29+
<Code buttonLabel={outsideButtonLabel}
2830
code={`<button class="btn btn-icon btn-minimal" data-bs-dismiss="${name}" data-bs-target="#my-${name}">\n <svg aria-hidden="true"><use xlink:href="${getVersionedDocsPath('/assets/img/ouds-web-sprite.svg#expurge')}"/></svg>\n <span class="visually-hidden">Close</span>\n</button>`}
2931
lang="html"
3032
/>

site/src/content/docs/components/alerts.mdx

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ The variants `.alert-negative`, `.alert-positive`, `.alert-info` and `.alert-war
192192
</div>`} />
193193

194194
<BootstrapCompatibility>
195-
<Example class="d-flex flex-column gap-medium" code={`<svg xmlns="http://www.w3.org/2000/svg" class="d-none">
195+
<Example buttonLabel="Bootstrap compatibility: functional alert message" class="d-flex flex-column gap-medium" code={`<svg xmlns="http://www.w3.org/2000/svg" class="d-none">
196196
<symbol id="check-circle-fill" viewBox="0 0 16 16">
197197
<path d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zm-3.97-3.03a.75.75 0 0 0-1.08.022L7.477 9.417 5.384 7.323a.75.75 0 0 0-1.06 1.06L6.97 11.03a.75.75 0 0 0 1.079-.02l3.992-4.99a.75.75 0 0 0-.01-1.05z"/>
198198
</symbol>
@@ -256,7 +256,7 @@ The variants alert neutral (default) and `.alert-accent` are considered as non-f
256256
</div>`} />
257257

258258
<BootstrapCompatibility>
259-
<Example class="d-flex flex-column gap-medium" code={`<svg xmlns="http://www.w3.org/2000/svg" class="d-none">
259+
<Example buttonLabel="Bootstrap compatibility: non-functional alert message" class="d-flex flex-column gap-medium" code={`<svg xmlns="http://www.w3.org/2000/svg" class="d-none">
260260
<symbol id="info-fill" viewBox="0 0 16 16">
261261
<path d="M8 16A8 8 0 1 0 8 0a8 8 0 0 0 0 16zm.93-9.412-1 4.705c-.07.34.029.533.304.533.194 0 .487-.07.686-.246l-.088.416c-.287.346-.92.598-1.465.598-.703 0-1.002-.422-.808-1.319l.738-3.468c.064-.293.006-.399-.287-.47l-.451-.081.082-.381 2.29-.287zM8 5.5a1 1 0 1 1 0-2 1 1 0 0 1 0 2z"/>
262262
</symbol>
@@ -283,7 +283,7 @@ In any case, the icon will be colorized automatically via the `color` attribute.
283283

284284
<Callout type="info" name="info-icons-svg-sprite" />
285285

286-
<Example buttonLabel="changed icon alert message" class="d-flex flex-column gap-medium" code={`<div class="alert alert-message">
286+
<Example buttonLabel="custom icon alert message" class="d-flex flex-column gap-medium" code={`<div class="alert alert-message">
287287
<div class="alert-icon">
288288
<svg aria-hidden="true">
289289
<use xlink:href="${getVersionedDocsPath('/assets/img/ouds-web-sprite.svg#heart-empty')}"/>
@@ -650,10 +650,8 @@ We use the following JavaScript to trigger our live alert demo:
650650

651651
Initialize elements as alerts.
652652

653-
```js
654-
const alertList = document.querySelectorAll('.alert')
655-
const alerts = [...alertList].map(element => new oudsWeb.Alert(element))
656-
```
653+
<Code buttonLabel="alerts initialization" lang="js" code={`const alertList = document.querySelectorAll('.alert')
654+
const alerts = [...alertList].map(element => new oudsWeb.Alert(element))`} />
657655

658656
<Callout type="info">
659657
For the sole purpose of dismissing an alert, it isn’t necessary to initialize the component manually via the JS API, unless you want to use one of our [methods](#methods). By making use of `data-bs-dismiss="alert"`, the component will be initialized automatically and properly dismissed.
@@ -671,9 +669,7 @@ const alerts = [...alertList].map(element => new oudsWeb.Alert(element))
671669

672670
You can create an alert instance with the alert constructor, for example:
673671

674-
```js
675-
const bsAlert = new oudsWeb.Alert('#myAlert')
676-
```
672+
<Code buttonLabel="alert instance creation" lang="js" code={`const bsAlert = new oudsWeb.Alert('#myAlert')`} />
677673

678674
This makes an alert listen for click events on descendant elements which have the `data-bs-dismiss="alert"` attribute. (Not necessary when using the data-api’s auto-initialization.)
679675

@@ -688,10 +684,8 @@ This makes an alert listen for click events on descendant elements which have th
688684

689685
Basic usage:
690686

691-
```js
692-
const alert = oudsWeb.Alert.getOrCreateInstance('#myAlert')
693-
alert.close()
694-
```
687+
<Code buttonLabel="alert basic usage" lang="js" code={`const alert = oudsWeb.Alert.getOrCreateInstance('#myAlert')
688+
alert.close()`} />
695689

696690
#### Events
697691

@@ -704,14 +698,12 @@ OUDS Web’s alert plugin exposes a few events for hooking into alert functional
704698
| `closed.bs.alert` | Fired when the alert has been closed and CSS transitions have completed. |
705699
</BsTable>
706700

707-
```js
708-
const myAlert = document.getElementById('myAlert')
701+
<Code buttonLabel="events listening" lang="js" code={`const myAlert = document.getElementById('myAlert')
709702
myAlert.addEventListener('closed.bs.alert', event => {
710703
// do something, for instance, explicitly move focus to the most appropriate element,
711704
// so it doesn’t get lost/reset to the start of the page
712705
// document.getElementById('...').focus()
713-
})
714-
```
706+
})`} />
715707

716708
## [[comp]] Inline alert
717709

site/src/content/docs/components/badges.mdx

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ Badge is displayed as a coloured shape, without an icon, text, or number; its se
9393
If the context does not allow visually impaired or blind users to understand the meaning, add a `.visually-hidden` text associated with the badge. [Read more about badges accessibility here](#accessibility).
9494
</Callout>
9595

96-
<Example class="" code={`<p class="badge"><span class="visually-hidden">Beware</span></p>
96+
<Example buttonLabel="badges accessible usage" code={`<p class="badge"><span class="visually-hidden">Beware</span></p>
9797
<p class="d-flex align-items-center">Beware<span class="badge ms-2xsmall"></span></p>`} />
9898

9999
### Variants
@@ -104,7 +104,7 @@ Badge is displayed as a coloured shape, without an icon, text, or number; its se
104104

105105
Non-functional badges are used to display neutral or accent information without carrying a specific functional meaning (unlike functional badges, see below).
106106

107-
<Example class="d-flex gap-large" code={`<p class="badge badge-neutral"><span class="visually-hidden">To be noted</span></p>
107+
<Example buttonLabel="non-functional badges" class="d-flex gap-large" code={`<p class="badge badge-neutral"><span class="visually-hidden">To be noted</span></p>
108108
<p class="badge badge-accent"><span class="visually-hidden">Important</span></p>`} />
109109

110110
##### Functional
@@ -115,14 +115,14 @@ Functional badges carry a clear meaning related to the status of an object or sy
115115
Keep in mind that color should not be the only way to convey information. Functional badges, which have a strong meaning, should not be combined, because some users cannot differentiate colors between them, for example colorblind people. In this case, it is preferable to use an icon as a second way to convey information, associated with a `.visually-hidden` text (required for screen reader users). [Read more about badges accessibility here](#accessibility).
116116
</Callout>
117117

118-
<Example class="d-flex gap-large" code={`<p class="badge badge-positive"><span class="visually-hidden">Success</span></p>
118+
<Example buttonLabel="functional badges" class="d-flex gap-large" code={`<p class="badge badge-positive"><span class="visually-hidden">Success</span></p>
119119
<p class="badge badge-info"><span class="visually-hidden">Info</span></p>
120120
<p class="badge badge-warning"><span class="visually-hidden">Warning</span></p>
121121
<p class="badge"><span class="visually-hidden">Beware</span></p>`} />
122122

123123
Here is a valid example of use of functional badges:
124124

125-
<Example class="d-flex gap-large" code={`<div class="d-flex align-items-center">
125+
<Example buttonLabel="functional badges usage" class="d-flex gap-large" code={`<div class="d-flex align-items-center">
126126
<p class="position-relative mb-none">
127127
Activities<span class="badge badge-info badge-small ms-2xsmall"></span><span class="visually-hidden">New!</span>
128128
</p>
@@ -146,7 +146,7 @@ Here is a valid example of use of functional badges:
146146

147147
The disabled state of a badge appears visually muted to signal that it is not currently active or relevant. To make a disabled badge, simply add the `.badge-disabled` class. Depending on the use case, the `.visually-hidden` text may be unnecessary or require adaptation.
148148

149-
<Example class="d-flex gap-large" code={`<p class="badge badge-neutral badge-disabled"></p>
149+
<Example buttonLabel="disabled badges" class="d-flex gap-large" code={`<p class="badge badge-neutral badge-disabled"></p>
150150
<p class="badge badge-accent badge-disabled"></p>
151151
<p class="badge badge-positive badge-disabled"></p>
152152
<p class="badge badge-info badge-disabled"></p>
@@ -157,7 +157,7 @@ The disabled state of a badge appears visually muted to signal that it is not cu
157157

158158
Badges are available in four sizes. Default size is medium.
159159

160-
<Example class="d-flex align-items-center gap-large" code={`
160+
<Example buttonLabel="badges sizes" class="d-flex align-items-center gap-large" code={`
161161
<p class="badge badge-xsmall"><span class="visually-hidden">Very small badge</span></p>
162162
<p class="badge badge-small"><span class="visually-hidden">Small badge</span></p>
163163
<p class="badge"><span class="visually-hidden">Medium badge (default)</span></p>
@@ -173,7 +173,7 @@ Badge - count is displayed as a coloured shape that shows numerical values, and
173173
If the number itself is not meaningful in the context, add a `.visually-hidden` text associated with the badge - count. [Read more about badges accessibility here](#accessibility).
174174
</Callout>
175175

176-
<Example class="d-flex gap-large" code={`<p class="badge badge-count">1<span class="visually-hidden">error</span></p>
176+
<Example buttonLabel="badges count" class="d-flex gap-large" code={`<p class="badge badge-count">1<span class="visually-hidden">error</span></p>
177177
<p class="position-relative pt-3xsmall">
178178
Error<span class="position-absolute top-0 start-100 translate-middle badge badge-count">1</span>
179179
</p>`} />
@@ -188,7 +188,7 @@ Badges - count can be used with non-functional or functional colors.
188188
Keep in mind that color should not be the only way to convey information. If the color has a strong meaning, especially in functional statuses, reflect that meaning in the `.visually hidden` text associated with the badge - count. [Read more about badges accessibility here](#accessibility).
189189
</Callout>
190190

191-
<Example class="d-flex gap-large" code={`<p class="badge badge-neutral badge-count">0<span class="visually-hidden">notification</span></p>
191+
<Example buttonLabel="status badges count" class="d-flex gap-large" code={`<p class="badge badge-neutral badge-count">0<span class="visually-hidden">notification</span></p>
192192
<p class="badge badge-accent badge-count">1<span class="visually-hidden">notification</span></p>
193193
<p class="badge badge-positive badge-count">2<span class="visually-hidden">confirmations</span></p>
194194
<p class="badge badge-info badge-count">10<span class="visually-hidden">new emails</span></p>
@@ -201,7 +201,7 @@ Badges - count can be used with non-functional or functional colors.
201201

202202
The disabled state of a badge - count appears visually muted to signal that it is not currently active or relevant. To make a disabled badge - count, simply add the `.badge-disabled` class. Depending on the use case, the `.visually-hidden` text may require adaptation.
203203

204-
<Example class="d-flex gap-large" code={`<p class="badge badge-neutral badge-count badge-disabled">0<span class="visually-hidden">notification</span></p>
204+
<Example buttonLabel="disabled badges count" class="d-flex gap-large" code={`<p class="badge badge-neutral badge-count badge-disabled">0<span class="visually-hidden">notification</span></p>
205205
<p class="badge badge-accent badge-count badge-disabled">1<span class="visually-hidden">notification</span></p>
206206
<p class="badge badge-positive badge-count badge-disabled">2<span class="visually-hidden">confirmations</span></p>
207207
<p class="badge badge-info badge-count badge-disabled">10<span class="visually-hidden">new emails</span></p>
@@ -212,7 +212,7 @@ The disabled state of a badge - count appears visually muted to signal that it i
212212

213213
Badges - count are available in two sizes. Add `.badge-large` to have a larger badge. Default size is medium.
214214

215-
<Example class="d-flex align-items-center gap-large" code={`<p class="badge badge-count">12<span class="visually-hidden">errors</span></p>
215+
<Example buttonLabel="badges count sizes" class="d-flex align-items-center gap-large" code={`<p class="badge badge-count">12<span class="visually-hidden">errors</span></p>
216216
<p class="badge badge-count badge-large">12<span class="visually-hidden">errors</span></p>`} />
217217

218218
## [[comp]] Badge - Icon
@@ -227,7 +227,7 @@ Badge - icon is presented as a coloured shape that displays an icon, and its sel
227227
Badges - icon should always be associated to a `.visually-hidden` text describing the icon's meaning. [Read more about badges accessibility here](#accessibility).
228228
</Callout>
229229

230-
<Example class="d-flex align-items-center gap-large" code={`<p class="badge">
230+
<Example buttonLabel="badges icon" class="d-flex align-items-center gap-large" code={`<p class="badge">
231231
<span class="badge-status-icon"></span>
232232
<span class="visually-hidden">Beware</span>
233233
</p>
@@ -250,7 +250,7 @@ Badge - icon is presented as a coloured shape that displays an icon, and its sel
250250

251251
Non-functional badges - icon are used to display neutral or accent information without carrying a specific functional meaning (unlike functional badges, see below), reinforced by an icon.
252252

253-
<Example class="d-flex gap-large" code={`<p class="badge badge-neutral">
253+
<Example buttonLabel="non-functional badges icon" class="d-flex gap-large" code={`<p class="badge badge-neutral">
254254
<svg class="badge-icon" aria-hidden="true">
255255
<use xlink:href="${getVersionedDocsPath('/assets/img/ouds-web-sprite.svg#heart-empty')}"/>
256256
</svg>
@@ -279,7 +279,7 @@ Functional badges - icon carry a clear meaning related to the status of an objec
279279
Keep in mind that color and icon should not be the only ways to convey information. In functional badges, the color and icon have a strong meaning, it must be reflected in the badge's `.visually-hidden` associated text. [Read more about tags accessibility here](#accessibility).
280280
</Callout>
281281

282-
<Example class="d-flex gap-large" code={`<p class="badge badge-positive">
282+
<Example buttonLabel="functional badges icon" class="d-flex gap-large" code={`<p class="badge badge-positive">
283283
<span class="badge-status-icon"></span>
284284
<span class="visually-hidden">Success</span>
285285
</p>
@@ -302,7 +302,7 @@ Functional badges - icon carry a clear meaning related to the status of an objec
302302

303303
The disabled state of a badge - icon appears visually muted to signal that it is not currently active or relevant. To make a disabled badge - icon, simply add the `.badge-disabled` class. Depending on the use case, the `.visually-hidden` text may be unnecessary or require adaptation.
304304

305-
<Example class="d-flex gap-large" code={`<p class="badge badge-disabled">
305+
<Example buttonLabel="disabled badges icon" class="d-flex gap-large" code={`<p class="badge badge-disabled">
306306
<span class="badge-status-icon"></span>
307307
</p>
308308
<p class="badge badge-neutral badge-disabled">
@@ -318,7 +318,7 @@ The disabled state of a badge - icon appears visually muted to signal that it is
318318

319319
Badges - icon are available in two sizes. Add `.badge-large` to have a larger badge. Default size is medium.
320320

321-
<Example class="d-flex align-items-center gap-large" code={`<p class="badge">
321+
<Example buttonLabel="badges icon sizes" class="d-flex align-items-center gap-large" code={`<p class="badge">
322322
<span class="badge-status-icon"></span>
323323
<span class="visually-hidden">Error</span>
324324
</p>
@@ -347,7 +347,7 @@ Badges - icon are available in two sizes. Add `.badge-large` to have a larger ba
347347

348348
Use utilities to modify a `.badge` and position it in the corner of a button.
349349

350-
<Example class="d-flex align-items-center gap-large" code={`<button type="button" class="btn btn-icon btn-default position-relative">
350+
<Example buttonLabel="badges positioning" class="d-flex align-items-center gap-large" code={`<button type="button" class="btn btn-icon btn-default position-relative">
351351
<svg class="icon" aria-hidden="true">
352352
<use xlink:href="${getVersionedDocsPath('/assets/img/ouds-web-sprite.svg#trash')}"/>
353353
</svg>
@@ -367,23 +367,21 @@ Use utilities to modify a `.badge` and position it in the corner of a button.
367367

368368
<BootstrapCompatibility>
369369

370-
<Example code={`<button type="button" class="btn btn-primary position-relative">
370+
<Example buttonLabel="Bootstrap compatibility: badge count positioning" code={`<button type="button" class="btn btn-primary position-relative">
371371
Inbox
372372
<span class="position-absolute top-0 start-100 translate-middle badge rounded-pill bg-danger">
373373
+99
374374
<span class="visually-hidden">unread messages</span>
375375
</span>
376376
</button>`} />
377377

378-
<Example code={`<button type="button" class="btn btn-primary position-relative">
378+
<Example buttonLabel="Bootstrap compatibility: badge positioning" code={`<button type="button" class="btn btn-primary position-relative">
379379
Profile
380380
<span class="position-absolute top-0 start-100 translate-middle p-small bg-danger border border-light rounded-circle">
381381
<span class="visually-hidden">New alerts</span>
382382
</span>
383383
</button>`} />
384384

385-
<Example code={getData('theme-colors').map((themeColor) => `<span class="badge text-bg-${themeColor.name}">+99</span>`)} />
386-
387-
<Example code={getData('theme-colors').map((themeColor) => `<span class="badge rounded-pill text-bg-${themeColor.name}">+99</span>`)} />
385+
<Example buttonLabel="Bootstrap compatibility: badges count" code={getData('theme-colors').map((themeColor) => `<span class="badge text-bg-${themeColor.name}">+99</span>`)} />
388386

389387
</BootstrapCompatibility>

0 commit comments

Comments
 (0)