Fix: Accessibility roles and aria labels by jhildenbiddle · Pull Request #2304 · docsifyjs/docsify · GitHub
Skip to content
2 changes: 2 additions & 0 deletions src/core/render/index.js
6 changes: 6 additions & 0 deletions src/core/render/progressbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ function init() {
const div = dom.create('div');

div.classList.add('progress');
div.setAttribute('role', 'progressbar');
div.setAttribute('aria-valuemin', '0');
div.setAttribute('aria-valuemax', '100');
div.setAttribute('aria-label', 'Loading...');
dom.appendTo(dom.body, div);
barEl = div;
}
Expand All @@ -33,13 +37,15 @@ export default function (info) {

barEl.style.opacity = 1;
barEl.style.width = num >= 95 ? '100%' : num + '%';
barEl.setAttribute('aria-valuenow', num >= 95 ? 100 : num);

if (num >= 95) {
clearTimeout(timeId);
// eslint-disable-next-line no-unused-vars
timeId = setTimeout(_ => {
barEl.style.opacity = 0;
barEl.style.width = '0%';
barEl.removeAttribute('aria-valuenow');
}, 200);
}
}
10 changes: 5 additions & 5 deletions src/core/render/tpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function main(config) {
<span></span><span></span><span></span>
</div>
</button>
<aside class="sidebar">
<aside class="sidebar" role="none">
${
config.name
? /* html */ `
Expand All @@ -52,14 +52,14 @@ export function main(config) {
`
: ''
}
<div class="sidebar-nav"><!--sidebar--></div>
<div class="sidebar-nav" role="navigation" aria-label="primary"><!--sidebar--></div>
</aside>
`;

return /* html */ `
<main>${aside}
<main role="presentation">${aside}
<section class="content">
<article class="markdown-section" id="main"><!--main--></article>
<article class="markdown-section" id="main" role="main"><!--main--></article>
</section>
</main>
`;
Expand All @@ -80,7 +80,7 @@ export function cover() {
`;

return /* html */ `
<section class="cover show" style="background: ${bgc}">
<section class="cover show" role="complementary" aria-label="cover" style="background: ${bgc}">
<div class="mask"></div>
<div class="cover-main"><!--cover--></div>
</section>
Expand Down
17 changes: 14 additions & 3 deletions src/plugins/search/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ function style() {
align-items: center;
}

.search .results-status:not(:empty) {
margin-top: 10px;
font-size: smaller;
}

.search .results-panel {
display: none;
}
Expand Down Expand Up @@ -122,12 +127,14 @@ function tpl(defaultValue = '') {
</svg>
</div>
</div>
<div class="results-status" aria-live="polite"></div>
<div class="results-panel"></div>
`;
const el = Docsify.dom.create('div', html);
const aside = Docsify.dom.find('aside');

Docsify.dom.toggleClass(el, 'search');
el.setAttribute('role', 'search');
Docsify.dom.before(aside, el);
}

Expand All @@ -136,12 +143,14 @@ function doSearch(value) {
const $panel = Docsify.dom.find($search, '.results-panel');
const $clearBtn = Docsify.dom.find($search, '.clear-button');
const $sidebarNav = Docsify.dom.find('.sidebar-nav');
const $status = Docsify.dom.find('div.search .results-status');
const $appName = Docsify.dom.find('.app-name');

if (!value) {
$panel.classList.remove('show');
$clearBtn.classList.remove('show');
$panel.innerHTML = '';
$status.textContent = '';

if (options.hideOtherSidebarContent) {
$sidebarNav && $sidebarNav.classList.remove('hide');
Expand All @@ -151,12 +160,12 @@ function doSearch(value) {
return;
}

const matchs = search(value);
const matches = search(value);

let html = '';
matchs.forEach(post => {
matches.forEach((post, i) => {
html += /* html */ `
<div class="matching-post">
<div class="matching-post" aria-label="search result ${i + 1}">
<a href="${post.url}">
<h2>${post.title}</h2>
<p>${post.content}</p>
Expand All @@ -168,6 +177,8 @@ function doSearch(value) {
$panel.classList.add('show');
$clearBtn.classList.add('show');
$panel.innerHTML = html || /* html */ `<p class="empty">${NO_DATA_TEXT}</p>`;
$status.textContent = `Found ${matches.length} results`;

if (options.hideOtherSidebarContent) {
$sidebarNav && $sidebarNav.classList.add('hide');
$appName && $appName.classList.add('hide');
Expand Down
8 changes: 4 additions & 4 deletions test/integration/__snapshots__/docs.test.js.snap