mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-20 18:17:51 +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--focus': focused,
|
||||||
'react-toggle--disabled': disabled,
|
'react-toggle--disabled': disabled,
|
||||||
})}>
|
})}>
|
||||||
|
{/* eslint-disable-next-line jsx-a11y/click-events-have-key-events */}
|
||||||
<div
|
<div
|
||||||
className="react-toggle-track"
|
className="react-toggle-track"
|
||||||
role="button"
|
role="button"
|
||||||
|
@ -73,6 +74,11 @@ const Toggle = memo(
|
||||||
onClick={() => setChecked(!checked)}
|
onClick={() => setChecked(!checked)}
|
||||||
onFocus={() => setFocused(true)}
|
onFocus={() => setFocused(true)}
|
||||||
onBlur={() => setFocused(false)}
|
onBlur={() => setFocused(false)}
|
||||||
|
onKeyDown={(e) => {
|
||||||
|
if (e.key === 'Enter') {
|
||||||
|
inputRef.current?.click();
|
||||||
|
}
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
|
@ -50,7 +50,11 @@ const Details = ({summary, children, ...props}: DetailsProps): JSX.Element => {
|
||||||
styles.details,
|
styles.details,
|
||||||
{[styles.isClient]: isClient},
|
{[styles.isClient]: isClient},
|
||||||
props.className,
|
props.className,
|
||||||
)}
|
)}>
|
||||||
|
{/* eslint-disable-next-line jsx-a11y/click-events-have-key-events */}
|
||||||
|
<div
|
||||||
|
role="button"
|
||||||
|
tabIndex={0}
|
||||||
onMouseDown={(e) => {
|
onMouseDown={(e) => {
|
||||||
const target = e.target as HTMLElement;
|
const target = e.target as HTMLElement;
|
||||||
// Prevent a double-click to highlight summary text
|
// 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>
|
<div className={styles.collapsibleContent}>{children}</div>
|
||||||
</Collapsible>
|
</Collapsible>
|
||||||
|
</div>
|
||||||
</details>
|
</details>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue