Skip to content

Commit 076037a

Browse files
committed
aria headings, labels, and announcements
1 parent 241dc32 commit 076037a

7 files changed

Lines changed: 40 additions & 34 deletions

File tree

src/components/api-request.js

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ export default class ApiRequest extends LitElement {
302302
}
303303

304304
return html`
305-
<div class="table-title top-gap">${title}${paramLocation === 'path' ? html`<span style='color:var(--red);'>*</span>` : ''}</div>
305+
<div class="table-title top-gap" role="heading" aria-level="${this.renderStyle === 'focused' ? 4 : 5}">${title}${paramLocation === 'path' ? html`<span style='color:var(--red);'>*</span>` : ''}</div>
306306
<div style="display:block; overflow-x:auto; max-width:100%;">
307307
<table role="presentation" class="m-table" style="width:100%; word-break:break-word;">
308308
${tableRows}
@@ -627,18 +627,21 @@ export default class ApiRequest extends LitElement {
627627
${!hasResponse ? '' : html`<button class="m-btn" part="btn btn-outline" @click="${this.clearResponseData}">${getI18nText('operations.clear-response')}</button>`}
628628
</div>
629629
<div class="tab-panel col" style="border-width:0 0 1px 0;">
630-
<div id="tab_buttons" class="tab-buttons row" @click="${(e) => {
631-
if (e.target.classList.contains('tab-btn') === false) { return; }
632-
this.activeResponseTab = e.target.dataset.tab;
633-
}}">
634-
<br>
635-
<div style="width: 100%">
636-
<button class="tab-btn ${!hasResponse || this.activeResponseTab === 'curl' ? 'active' : ''}" data-tab = 'curl'>${getI18nText('operations.request')}</button>
637-
${!hasResponse ? '' : html`
638-
<button class="tab-btn ${this.activeResponseTab === 'response' ? 'active' : ''}" data-tab = 'response'>${getI18nText('operations.response')}</button>
639-
<button class="tab-btn ${this.activeResponseTab === 'headers' ? 'active' : ''}" data-tab = 'headers'>${getI18nText('operations.response-headers')}</button>`
640-
}
641-
</div>
630+
${hasResponse
631+
? html`
632+
<div id="tab_buttons" class="tab-buttons row" role="group" @click="${(e) => {
633+
if (e.target.classList.contains('tab-btn') === false) { return; }
634+
this.activeResponseTab = e.target.dataset.tab;
635+
}}">
636+
<button class="tab-btn ${this.activeResponseTab === 'curl' ? 'active' : ''}" aria-current="${this.activeResponseTab === 'curl'}" data-tab = 'curl'>${getI18nText('operations.request')}</button>
637+
<button class="tab-btn ${this.activeResponseTab === 'response' ? 'active' : ''}" aria-current="${this.activeResponseTab === 'response'}" data-tab = 'response'>${getI18nText('operations.response')}</button>
638+
<button class="tab-btn ${this.activeResponseTab === 'headers' ? 'active' : ''}" aria-current="${this.activeResponseTab === 'headers'}" data-tab = 'headers'>${getI18nText('operations.response-headers')}</button>
639+
</div>`
640+
: html`
641+
<div id="tab_buttons" class="tab-buttons row">
642+
<div class="tab-btn active" role="heading" aria-level="${this.renderStyle === 'focused' ? 4 : 5}" data-tab = 'curl'>${getI18nText('operations.request')}</div>
643+
</div>`
644+
}
642645
</div>
643646
${this.responseIsBlob
644647
? html`
@@ -659,14 +662,14 @@ export default class ApiRequest extends LitElement {
659662
</div>`
660663
: html`
661664
<div class="tab-content col m-markdown" style="flex:1; display:${this.activeResponseTab === 'response' ? 'flex' : 'none'};" >
662-
<syntax-highlighter style="min-height: 60px" mime-type="${this.responseContentType}" .content="${this.responseText}"/>
665+
<syntax-highlighter style="min-height: 60px" mime-type="${this.responseContentType}" .content="${this.responseText}" aria-label="Response text"/>
663666
</div>`
664667
}
665668
<div class="tab-content col m-markdown" style="flex:1;display:${this.activeResponseTab === 'headers' ? 'flex' : 'none'};" >
666-
<syntax-highlighter style="min-height: 60px" language="http" .content="${this.responseHeaders}"/>
669+
<syntax-highlighter style="min-height: 60px" language="http" .content="${this.responseHeaders}" aria-label="Response headers"/>
667670
</div>
668671
<div class="tab-content m-markdown col" style="flex:1;display:${this.activeResponseTab === 'curl' ? 'flex' : 'none'};">
669-
<syntax-highlighter style="min-height: 60px" language="shell" .content="${curlSyntax.trim()}"/>
672+
<syntax-highlighter style="min-height: 60px" language="shell" .content="${curlSyntax.trim()}" aria-label="Request example"/>
670673
</div>
671674
</div>`;
672675
}

src/components/api-response.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ export default class ApiResponse extends LitElement {
275275
? html`
276276
${mimeRespDetails.examples[0].exampleSummary && mimeRespDetails.examples[0].exampleSummary.length > 80 ? html`<div style="padding: 4px 0"> ${mimeRespDetails.examples[0].exampleSummary} </div>` : ''}
277277
${mimeRespDetails.examples[0].exampleDescription ? html`<div class="m-markdown-small" style="padding: 4px 0"> ${unsafeHTML(toMarkdown(mimeRespDetails.examples[0].exampleDescription || ''))} </div>` : ''}
278-
<syntax-highlighter class='example-panel generic-tree pad-top-8' mime-type="${mimeRespDetails.examples[0].exampleType}" .content="${mimeRespDetails.examples[0].exampleValue}"/>`
278+
<syntax-highlighter class='example-panel generic-tree pad-top-8' mime-type="${mimeRespDetails.examples[0].exampleType}" .content="${mimeRespDetails.examples[0].exampleValue}" aria-label="Response example"/>`
279279
: html`
280280
<span class = 'example-panel generic-tree ${this.renderStyle === 'read' ? 'border pad-8-16' : 'border-top pad-top-8'}'>
281281
<select aria-label='response body example' @change='${(e) => this.onSelectExample(e)}'>
@@ -287,7 +287,7 @@ export default class ApiResponse extends LitElement {
287287
<div class="example" data-example = '${v.exampleId}' style = "display: ${v.exampleId === mimeRespDetails.selectedExample ? 'block' : 'none'}">
288288
${v.exampleSummary && v.exampleSummary.length > 80 ? html`<div style="padding: 4px 0"> ${v.exampleSummary} </div>` : ''}
289289
${v.exampleDescription && v.exampleDescription !== v.exampleSummary ? html`<div class="m-markdown-small" style="padding: 4px 0"> ${unsafeHTML(toMarkdown(v.exampleDescription || ''))} </div>` : ''}
290-
<syntax-highlighter mime-type="${v.exampleType}" .content="${v.exampleValue}"/>
290+
<syntax-highlighter mime-type="${v.exampleType}" .content="${v.exampleValue}" aria-label="Response example"/>
291291
</div>
292292
`)}
293293
</span>

src/components/request-form-table.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function generateFormRows(data, options, dataType = 'object', key = '', descript
4848
${data['::type'] === 'xxx-of-option' || key.startsWith('::OPTION')
4949
? html`<span class="xxx-of-key">${keyLabel}</span><span class="${isOneOfLabel ? 'xxx-of-key' : 'xxx-of-descr'}">${keyDescr}</span>`
5050
: isRequired
51-
? html`<span class="key-label requiredStar" style="display:inline-block;" title="Required">${keyLabel}</span>`
51+
? html`<span class="key-label requiredStar" style="display:inline-block;" role="img" aria-label=" (Required)" title="Required">${keyLabel}</span>`
5252
: html`<span class="key-label" style="display:inline-block;">${keyLabel === '::props' ? '' : keyLabel}</span>`
5353
}
5454
</div>

src/components/schema-tree.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ export default class SchemaTree extends LitElement {
249249
? ''
250250
: schemaLevel > 0
251251
? html`<span class="key-label">
252-
${keyLabel.replace(/\*$/, '')}${keyLabel.endsWith('*') ? html`<span class="requiredStar" title="Required"></span>` : ''}:
252+
${keyLabel.replace(/\*$/, '')}${keyLabel.endsWith('*') ? html`<span class="requiredStar" role="img" aria-label=" (Required)" title="Required"></span>` : ''}:
253253
</span>`
254254
: ''
255255
}
@@ -296,7 +296,7 @@ export default class SchemaTree extends LitElement {
296296
<div class="tr">
297297
<div class="td key ${deprecated ? 'deprecated' : ''}" style='min-width:${minFieldColWidth}px'>
298298
${keyLabel.endsWith('*')
299-
? html`<span class="key-label requiredStar" title="Required">${keyLabel.substring(0, keyLabel.length - 1)}</span>:`
299+
? html`<span class="key-label requiredStar" role="img" aria-label=" (Required)" title="Required">${keyLabel.substring(0, keyLabel.length - 1)}</span>:`
300300
: key.startsWith('::OPTION')
301301
? html`<span class='key-label xxx-of-key'>${keyLabel}</span><span class="xxx-of-descr">${keyDescr}</span>`
302302
: schemaLevel > 0

src/components/syntax-highlighter.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class SyntaxHighlighter extends LitElement {
4747
content: { type: Object },
4848
language: { type: String, attribute: 'language' },
4949
mimeType: { type: String, attribute: 'mime-type' },
50+
label: { type: String, attribute: 'aria-label' },
5051
};
5152
}
5253

@@ -96,7 +97,7 @@ class SyntaxHighlighter extends LitElement {
9697
}
9798

9899
render() {
99-
return this.renderCopyWrapper(this.renderHighlight());
100+
return this.renderCopyWrapper(this.renderHighlight(), this.label?.toLowerCase());
100101
}
101102

102103
/**
@@ -123,11 +124,13 @@ class SyntaxHighlighter extends LitElement {
123124
* @param {*} content Content
124125
* @returns Content
125126
*/
126-
renderCopyWrapper(content) {
127+
renderCopyWrapper(content, label) {
127128
return html`<div class="fs-exclude ph-no-capture" data-hj-suppress data-sl="mask" style="min-height: 2rem;">
128129
<button
129130
class="m-btn outline-primary toolbar-copy-btn"
130-
@click='${this.copyToClipboard}'
131+
@click='${this.copyToClipboard}'
132+
aria-label="Copy ${label}"
133+
aria-live="polite"
131134
part="btn btn-fill btn-copy">${getI18nText('operations.copy')}</button>
132135
${content}
133136
</div>`;

src/templates/security-scheme-template.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ function renderSecurityScheme(v) {
332332
: html`Sends the <code>Authorization header</code> containing the token type <code style="text-transform: capitalize;">${v.scheme || 'bearer'}</code> followed by the <code>${v.bearerFormat ?? 'Token'}</code> string.`
333333
}
334334
</div>
335-
<form style="height: 50px; margin-top: 1rem; padding: 10px 0; margin-bottom: 10px;">
335+
<form style="height: 50px; margin-top: 1rem; padding: 10px 0; margin-bottom: 10px;" aria-live="polite">
336336
${v.in === 'cookie'
337337
? html`
338338
<div style="display: block">
@@ -343,7 +343,7 @@ function renderSecurityScheme(v) {
343343
</small>
344344
</div>`
345345
: !v.finalKeyValue ? html`
346-
<input autocomplete="on" name="api-key" type="text" value="${v.value}" placeholder="${v.bearerFormat ?? 'api-token'}"
346+
<input autocomplete="on" name="api-key" type="text" value="${v.value}" aria-label="${v.bearerFormat ?? 'API token'}"
347347
spellcheck="false" class="api-key-input fs-exclude ph-no-capture" data-hj-suppress data-sl="mask">
348348
<button type="submit" class="m-btn thin-border" style = "margin-left:5px;"
349349
part = "btn btn-outline"
@@ -363,7 +363,7 @@ function renderSecurityScheme(v) {
363363
code { font-weight: bold; }
364364
</style>
365365
<div style="padding-top: 1rem">${unsafeHTML(getI18nText('authentication.http-basic-desc'))}</div>
366-
<div style="height: 50px; margin-top: 1rem; padding: 10px 0; margin-bottom: 10px;">
366+
<div style="height: 50px; margin-top: 1rem; padding: 10px 0; margin-bottom: 10px;" aria-role="status">
367367
<span class="blue-text" style="margin-right: 1rem">Key Applied</span>
368368
<button class="m-btn thin-border small" part="btn btn-outline" @click=${() => { v.finalKeyValue = ''; this.requestUpdate(); }}>${getI18nText('authentication.remove')}</button>
369369
</div>`;
@@ -407,7 +407,7 @@ export default function securitySchemeTemplate() {
407407
<slot name="authentication-header">
408408
<div class="sub-title regular-font" role="heading" aria-level="2">${getI18nText('headers.authentication')}</div>
409409
</slot>
410-
<div class="small-font-size" style="display:flex; align-items: center; min-height:40px">
410+
<div class="small-font-size" style="display:flex; align-items: center; min-height:40px" aria-role="status">
411411
${providedApiKeys.length > 0
412412
? html`
413413
<div class="blue-text"> ${providedApiKeys.length} API key applied </div>
@@ -498,20 +498,20 @@ export function pathSecurityTemplate(pathSecurityOptions) {
498498
securityDefs: andSecurityKeys1,
499499
});
500500
});
501-
return html`<div class="security-info-button" data-content-id='auth' @click='${(e) => this.scrollToEventTarget(e, false)}'>
501+
return html`<div class="security-info-button">
502502
<div style="position:relative; display:flex; min-width:350px; max-width:700px; justify-content: flex-end;">
503-
<svg width="16" height="24" style="cursor: pointer;">
503+
<svg width="16" height="24" style="cursor: pointer;" role="img" aria-label="Security">
504504
<g>
505505
<path style="fill: var(--fg3)" d="m13.8,8.5l0,-2.6l0,0c0,-3.2 -2.6,-5.8 -5.8,-5.8s-5.8,2.6 -5.8,5.8l0,0l0,2.6l-2.1,0l0,11.2l16,0l0,-11.2l-2.1,0l-0,0l0,0l0,0l-0,0zm-9.8,-2.6c0,0 0,0 0,0c0,-2.2 1.8,-4 4,-4c2.2,0 4,1.8 4,4c0,0 0,0 0,0l0,2.6l-8.03,0l0,-2.6l0,0l0,0z" />
506506
</g>
507507
</svg>
508508
${orSecurityKeys1.map((orSecurityItem1, i) => html`
509509
${i !== 0 ? html`<div style="padding:3px 4px;"> OR </div>` : ''}
510-
<div class="security-tooltip tooltip" style="cursor: pointer;">
510+
<div class="security-tooltip tooltip" style="cursor: pointer;" aria-describedby="tooltip-security-info" data-content-id="auth" role="link" tabindex="0" @click='${(e) => this.scrollToEventTarget(e, false)}' @keydown="${(e) => { if (e.key === 'Enter') { e.target.click(); }}}">
511511
<div style="padding:2px 4px; white-space:nowrap; text-overflow:ellipsis;max-width:150px; overflow:hidden;">
512512
<span part="anchor anchor-operation-security"> ${orSecurityItem1.securityTypes} </span>
513513
</div>
514-
<div class="tooltip-text" style="position:absolute; color: var(--fg); top:26px; right:0; border:1px solid var(--border-color);padding:2px 4px; display:block;">
514+
<div class="tooltip-text" id="tooltip-security-info" role="tooltip" style="position:absolute; color: var(--fg); top:26px; right:0; border:1px solid var(--border-color);padding:2px 4px; display:block;">
515515
${orSecurityItem1.securityDefs.length > 1 ? html`<div>Requires <b>all</b> of the following </div>` : ''}
516516
<div style="padding-left: 8px">
517517
${orSecurityItem1.securityDefs.map((andSecurityItem, j) => html`

src/templates/server-template.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ export default function serverTemplate() {
7878
}
7979
return html`
8080
<section id = 'servers' part="section-servers" style="margin-top:24px; margin-bottom:24px;" class='regular-font observe-me section-padding ${this.renderStyle === 'read' ? 'section-gap--read-mode' : (this.renderStyle === 'focused' ? 'section-gap--focused-mode' : 'section-gap')}'>
81-
<div class = 'sub-title' role="heading" aria-level="2">${getI18nText('headers.api-servers')}</div>
82-
<div class = 'mono-font' style='margin: 12px 0; font-size:calc(var(--font-size-small) + 1px);'>
81+
<div class = 'sub-title' role="heading" aria-level="2" id="servers-title">${getI18nText('headers.api-servers')}</div>
82+
<div class = 'mono-font' style='margin: 12px 0; font-size:calc(var(--font-size-small) + 1px);' role='radiogroup' aria-labelledby='servers-title'>
8383
${!this.resolvedSpec.servers || !this.resolvedSpec.servers.length
8484
? ''
8585
: html`

0 commit comments

Comments
 (0)