Skip to content

Commit

Permalink
Merge pull request #5077 from marcoscv-work/accessibility2
Browse files Browse the repository at this point in the history
feat(clayui.com): Add key shortcut keys by platform type and hiding it in mobile
  • Loading branch information
pat270 authored Sep 7, 2022
2 parents 2cb4508 + e6a5561 commit 74e0edd
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 18 deletions.
49 changes: 32 additions & 17 deletions clayui.com/src/components/LayoutNav/Search.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
* SPDX-License-Identifier: BSD-3-Clause
*/

import React, {useEffect} from 'react';
import React, {useEffect, useRef} from 'react';

export default (props) => {
const autocompleteRef = useRef();
useEffect(() => {
if (window.docsearch) {
window.docsearch({
Expand All @@ -14,27 +15,41 @@ export default (props) => {
inputSelector: '#algolia-doc-search',
});
}

const platform = (
navigator?.userAgentData?.platform || navigator?.platform
).toLowerCase();

if (platform.includes('mac')) {
autocompleteRef.current.setAttribute('data-platform', 'mac');
} else if (platform.includes('linux')) {
autocompleteRef.current.setAttribute('data-platform', 'linux');
}
}, []);

return (
<div className="page-autocomplete">
<div className="input-group">
<input
className="form-control"
id="algolia-doc-search"
name="q"
placeholder={props.placeholder}
required
type="text"
/>
<div className="platform" ref={autocompleteRef}>
<div className="page-autocomplete">
<div className="input-group">
<input
className="form-control"
id="algolia-doc-search"
name="q"
placeholder={props.placeholder}
required
type="text"
/>

<span className="input-group-addon">
<kbd className="mr-2">K</kbd>
<span aria-hidden="true" className="input-group-addon">
<span className="c-kbd c-kbd-sm d-md-block d-none mr-2">
<kbd className="c-kbd">K</kbd>
</span>

<svg className="lexicon-icon">
<use xlinkHref="/images/icons/icons.svg#search" />
</svg>
</span>
<svg className="lexicon-icon">
<use xlinkHref="/images/icons/icons.svg#search" />
</svg>
</span>
</div>
</div>
</div>
);
Expand Down
20 changes: 19 additions & 1 deletion clayui.com/src/styles/_autocomplete.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@
top: 50%;
z-index: 9;

> .c-kbd {
&:before {
content: 'ctrl + ';
}

@at-root [data-platform='mac'] &:before {
content: 'ctrl + ⌥ + ';
}

@at-root [data-platform='linux'] &:before {
content: 'alt + ';
}
}

.lexicon-icon {
margin-top: 0;
}
Expand All @@ -25,7 +39,11 @@
background-color: white;
border-radius: 4px;
padding-left: 0.875rem;
padding-right: $base-size * 2.5;
padding-right: $base-size * 4;

@at-root [data-platform='mac'] & {
padding-right: $base-size * 5;
}

&::-moz-placeholder {
opacity: 1;
Expand Down

0 comments on commit 74e0edd

Please sign in to comment.