mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-19 17:49:19 +02:00
polish: bind key listener to light/dark toggle + a11y lint fixes (#5341)
* Fix Details a11y Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * Remove keydown logic Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * Fix toggle Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * Proper way to fix toggle Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * Proper way to fix details Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * Put callback back Signed-off-by: Josh-Cena <sidachen2003@gmail.com>
This commit is contained in:
parent
cbff487516
commit
69b11a8546
2 changed files with 46 additions and 35 deletions
|
@ -53,6 +53,7 @@ const Toggle = memo(
|
|||
'react-toggle--focus': focused,
|
||||
'react-toggle--disabled': disabled,
|
||||
})}>
|
||||
{/* eslint-disable-next-line jsx-a11y/click-events-have-key-events */}
|
||||
<div
|
||||
className="react-toggle-track"
|
||||
role="button"
|
||||
|
@ -73,6 +74,11 @@ const Toggle = memo(
|
|||
onClick={() => setChecked(!checked)}
|
||||
onFocus={() => setFocused(true)}
|
||||
onBlur={() => setFocused(false)}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter') {
|
||||
inputRef.current?.click();
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
|
|
@ -50,7 +50,11 @@ const Details = ({summary, children, ...props}: DetailsProps): JSX.Element => {
|
|||
styles.details,
|
||||
{[styles.isClient]: isClient},
|
||||
props.className,
|
||||
)}
|
||||
)}>
|
||||
{/* eslint-disable-next-line jsx-a11y/click-events-have-key-events */}
|
||||
<div
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
onMouseDown={(e) => {
|
||||
const target = e.target as HTMLElement;
|
||||
// Prevent a double-click to highlight summary text
|
||||
|
@ -87,6 +91,7 @@ const Details = ({summary, children, ...props}: DetailsProps): JSX.Element => {
|
|||
}}>
|
||||
<div className={styles.collapsibleContent}>{children}</div>
|
||||
</Collapsible>
|
||||
</div>
|
||||
</details>
|
||||
);
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue