Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add missed labels to elements #1445

Merged
merged 5 commits into from
Nov 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions demo/ComboBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ export default class ComboBox extends React.Component<ComboBoxProps, ComboBoxSta
onFocus={this.open}
onBlur={this.handleBlur}
onKeyDown={this.handleKeyPress}
aria-label="URL to an OpenAPI definition to try"
/>
<Button onClick={this.handleTryItClick}> TRY IT </Button>
{open && <DropDownList>{options.map(this.renderOption)}</DropDownList>}
Expand Down
5 changes: 4 additions & 1 deletion demo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ class DemoApp extends React.Component<
<>
<Heading>
<a href=".">
<Logo src="https://github.com/Redocly/redoc/raw/master/docs/images/redoc-logo.png" />
<Logo
src="https://github.com/Redocly/redoc/raw/master/docs/images/redoc-logo.png"
alt="Redoc logo"
/>
</a>
<ControlsContainer>
<ComboBox
Expand Down
1 change: 1 addition & 0 deletions src/common-elements/linkify.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export class Link extends React.Component<{ to: string; className?: string; chil
className={this.props.className}
href={store!.menu.history.linkForId(this.props.to)}
onClick={this.navigate.bind(this, store!.menu.history)}
aria-label={this.props.to}
>
{this.props.children}
</a>
Expand Down
10 changes: 8 additions & 2 deletions src/components/JsonViewer/JsonViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ class Json extends React.PureComponent<JsonProps> {
expandAll = () => {
const elements = this.node.getElementsByClassName('collapsible');
for (const collapsed of Array.prototype.slice.call(elements)) {
(collapsed.parentNode as Element)!.classList.remove('collapsed');
const parentNode = collapsed.parentNode as Element;
parentNode.classList.remove('collapsed');
parentNode.querySelector('.collapser')!.setAttribute('aria-label', 'collapse');
}
};

Expand All @@ -61,7 +63,9 @@ class Json extends React.PureComponent<JsonProps> {
const elementsArr = Array.prototype.slice.call(elements, 1);

for (const expanded of elementsArr) {
(expanded.parentNode as Element)!.classList.add('collapsed');
const parentNode = expanded.parentNode as Element;
parentNode.classList.add('collapsed');
parentNode.querySelector('.collapser')!.setAttribute('aria-label', 'expand');
}
};

Expand All @@ -71,8 +75,10 @@ class Json extends React.PureComponent<JsonProps> {
collapsed = target.parentElement!.getElementsByClassName('collapsible')[0];
if (collapsed.parentElement.classList.contains('collapsed')) {
collapsed.parentElement.classList.remove('collapsed');
target.setAttribute('aria-label', 'collapse');
} else {
collapsed.parentElement.classList.add('collapsed');
target.setAttribute('aria-label', 'expand');
}
}
};
Expand Down
7 changes: 6 additions & 1 deletion src/components/Schema/DiscriminatorDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ export class DiscriminatorDropdown extends React.Component<{
this.sortOptions(options, enumValues);

return (
<StyledDropdown value={activeValue} options={options} onChange={this.changeActiveChild} />
<StyledDropdown
value={activeValue}
options={options}
onChange={this.changeActiveChild}
ariaLabel="Example"
/>
);
}

Expand Down
1 change: 1 addition & 0 deletions src/components/SearchBox/SearchBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ export class SearchBox extends React.PureComponent<SearchBoxProps, SearchBoxStat
value={this.state.term}
onKeyDown={this.handleKeyDown}
placeholder="Search..."
aria-label="Search"
type="text"
onChange={this.search}
/>
Expand Down
12 changes: 6 additions & 6 deletions src/utils/jsonToHtml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ function valueToHTML(value, maxExpandLevel: number) {

function arrayToHTML(json, maxExpandLevel: number) {
const collapsed = level > maxExpandLevel ? 'collapsed' : '';
let output = `<button class="collapser"></button>${punctuation(
'[',
)}<span class="ellipsis"></span><ul class="array collapsible">`;
let output = `<button class="collapser" aria-label="${
level > maxExpandLevel + 1 ? 'expand' : 'collapse'
}"></button>${punctuation('[')}<span class="ellipsis"></span><ul class="array collapsible">`;
let hasContents = false;
const length = json.length;
for (let i = 0; i < length; i++) {
Expand All @@ -98,9 +98,9 @@ function objectToHTML(json, maxExpandLevel: number) {
const collapsed = level > maxExpandLevel ? 'collapsed' : '';
const keys = Object.keys(json);
const length = keys.length;
let output = `<button class="collapser"></button>${punctuation(
'{',
)}<span class="ellipsis"></span><ul class="obj collapsible">`;
let output = `<button class="collapser" aria-label="${
level > maxExpandLevel + 1 ? 'expand' : 'collapse'
}"></button>${punctuation('{')}<span class="ellipsis"></span><ul class="obj collapsible">`;
let hasContents = false;
for (let i = 0; i < length; i++) {
const key = keys[i];
Expand Down