fix(v2): docsearch a11y issue (#1449)

This commit is contained in:
Endi 2019-05-11 22:47:22 +07:00 committed by Yangshun Tay
parent 6136fbe1d2
commit 070723697f
4 changed files with 12 additions and 6 deletions

View file

@ -11,8 +11,8 @@
"@babel/parser": "^7.4.3", "@babel/parser": "^7.4.3",
"@babel/traverse": "^7.4.3", "@babel/traverse": "^7.4.3",
"@mapbox/rehype-prism": "^0.3.1", "@mapbox/rehype-prism": "^0.3.1",
"@mdx-js/mdx": "^1.0.14", "@mdx-js/mdx": "^1.0.18",
"@mdx-js/react": "^1.0.6", "@mdx-js/react": "^1.0.16",
"github-slugger": "^1.2.1", "github-slugger": "^1.2.1",
"loader-utils": "^1.2.3", "loader-utils": "^1.2.3",
"mdast-util-to-string": "^1.0.5", "mdast-util-to-string": "^1.0.5",

View file

@ -8,7 +8,7 @@
}, },
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"docsearch.js": "^2.5.2" "docsearch.js": "^2.6.x"
}, },
"peerDependencies": { "peerDependencies": {
"@docusaurus/core": "^2.0.0", "@docusaurus/core": "^2.0.0",

View file

@ -28,6 +28,11 @@ class Search extends React.Component {
// https://github.com/algolia/docsearch/issues/352 // https://github.com/algolia/docsearch/issues/352
const isClient = typeof window !== 'undefined'; const isClient = typeof window !== 'undefined';
if (isClient) { if (isClient) {
// Temporary workaround for a11y issue
// https://github.com/algolia/docsearch/issues/418#
const docsearchInput = document.querySelector('#search_input_react');
const ariaLabel = docsearchInput.getAttribute('aria-label');
import('docsearch.js').then(({default: docsearch}) => { import('docsearch.js').then(({default: docsearch}) => {
docsearch({ docsearch({
appId: algolia.appId, appId: algolia.appId,
@ -36,6 +41,7 @@ class Search extends React.Component {
inputSelector: '#search_input_react', inputSelector: '#search_input_react',
algoliaOptions: algolia.algoliaOptions, algoliaOptions: algolia.algoliaOptions,
}); });
docsearchInput.setAttribute('aria-label', ariaLabel);
}); });
} else { } else {
console.warn('Search has failed to load and now is being disabled'); console.warn('Search has failed to load and now is being disabled');

View file

@ -1599,7 +1599,7 @@
refractor "^2.3.0" refractor "^2.3.0"
unist-util-visit "^1.1.3" unist-util-visit "^1.1.3"
"@mdx-js/mdx@^1.0.14": "@mdx-js/mdx@^1.0.18":
version "1.0.18" version "1.0.18"
resolved "https://registry.yarnpkg.com/@mdx-js/mdx/-/mdx-1.0.18.tgz#42bb35e36b7566aed88c5c11a381705f974bc03b" resolved "https://registry.yarnpkg.com/@mdx-js/mdx/-/mdx-1.0.18.tgz#42bb35e36b7566aed88c5c11a381705f974bc03b"
integrity sha512-KO2odMrZC77Yf9bhL0Qu0GtvVivVV6dL5DWJeuMeSkc9wkL9fBT06re67TfgeJ37R+lyslkG+uPUahIj4/SOoQ== integrity sha512-KO2odMrZC77Yf9bhL0Qu0GtvVivVV6dL5DWJeuMeSkc9wkL9fBT06re67TfgeJ37R+lyslkG+uPUahIj4/SOoQ==
@ -1620,7 +1620,7 @@
unist-builder "^1.0.1" unist-builder "^1.0.1"
unist-util-visit "^1.3.0" unist-util-visit "^1.3.0"
"@mdx-js/react@^1.0.6": "@mdx-js/react@^1.0.16":
version "1.0.16" version "1.0.16"
resolved "https://registry.yarnpkg.com/@mdx-js/react/-/react-1.0.16.tgz#414c3fce49493a4c60e5590cfc0a2a07efc19f38" resolved "https://registry.yarnpkg.com/@mdx-js/react/-/react-1.0.16.tgz#414c3fce49493a4c60e5590cfc0a2a07efc19f38"
integrity sha512-HJJO8LYogt9UT4TP3+TVeokMj0lgwCONKlcOfr7VMb38Z6DDE3Ydvi+M3iScUea2DfifS4kGztgJ7zH6HXynTw== integrity sha512-HJJO8LYogt9UT4TP3+TVeokMj0lgwCONKlcOfr7VMb38Z6DDE3Ydvi+M3iScUea2DfifS4kGztgJ7zH6HXynTw==
@ -4607,7 +4607,7 @@ dns-txt@^2.0.2:
dependencies: dependencies:
buffer-indexof "^1.0.0" buffer-indexof "^1.0.0"
docsearch.js@^2.5.2: docsearch.js@^2.5.2, docsearch.js@^2.6.x:
version "2.6.2" version "2.6.2"
resolved "https://registry.yarnpkg.com/docsearch.js/-/docsearch.js-2.6.2.tgz#cb36a97aeac8a8d31eed5915cdee808a2248b41c" resolved "https://registry.yarnpkg.com/docsearch.js/-/docsearch.js-2.6.2.tgz#cb36a97aeac8a8d31eed5915cdee808a2248b41c"
integrity sha512-qyQ+raZlHSkfdpFg8wJNhjiz9WsjdQkRGe2LiiKS6vIIsouNNole2Kg/9UvGoUIK9PLLl31uL3I4YDwnrXt5yQ== integrity sha512-qyQ+raZlHSkfdpFg8wJNhjiz9WsjdQkRGe2LiiKS6vIIsouNNole2Kg/9UvGoUIK9PLLl31uL3I4YDwnrXt5yQ==