mirror of
https://github.com/logto-io/logto.git
synced 2025-01-20 21:32:31 -05:00
refactor(console): add a11y for language editor components (#2123)
This commit is contained in:
parent
ad5b7b1aea
commit
44772ba2e1
2 changed files with 27 additions and 13 deletions
|
@ -7,6 +7,7 @@ import Plus from '@/assets/images/plus.svg';
|
||||||
import SearchIcon from '@/assets/images/search.svg';
|
import SearchIcon from '@/assets/images/search.svg';
|
||||||
import Button from '@/components/Button';
|
import Button from '@/components/Button';
|
||||||
import TextInput from '@/components/TextInput';
|
import TextInput from '@/components/TextInput';
|
||||||
|
import { onKeyDownHandler } from '@/utilities/a11y';
|
||||||
|
|
||||||
import * as style from './AddLanguageSelector.module.scss';
|
import * as style from './AddLanguageSelector.module.scss';
|
||||||
|
|
||||||
|
@ -54,6 +55,12 @@ const AddLanguageSelector = ({ options, onSelect }: Props) => {
|
||||||
};
|
};
|
||||||
}, [isDropDownOpen, searchInputRef]);
|
}, [isDropDownOpen, searchInputRef]);
|
||||||
|
|
||||||
|
const handleSelect = (languageTag: LanguageTag) => {
|
||||||
|
onSelect(languageTag);
|
||||||
|
setIsDropDownOpen(false);
|
||||||
|
setSearchInputValue('');
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div ref={selectorRef} className={style.languageSelector}>
|
<div ref={selectorRef} className={style.languageSelector}>
|
||||||
<div className={style.input}>
|
<div className={style.input}>
|
||||||
|
@ -81,15 +88,16 @@ const AddLanguageSelector = ({ options, onSelect }: Props) => {
|
||||||
{isDropDownOpen && filteredOptions.length > 0 && (
|
{isDropDownOpen && filteredOptions.length > 0 && (
|
||||||
<ul className={style.dropDown}>
|
<ul className={style.dropDown}>
|
||||||
{filteredOptions.map((languageTag) => (
|
{filteredOptions.map((languageTag) => (
|
||||||
// TODO: @yijun
|
|
||||||
// eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-noninteractive-element-interactions
|
|
||||||
<li
|
<li
|
||||||
key={languageTag}
|
key={languageTag}
|
||||||
|
role="tab"
|
||||||
|
tabIndex={0}
|
||||||
className={style.dropDownItem}
|
className={style.dropDownItem}
|
||||||
|
onKeyDown={onKeyDownHandler(() => {
|
||||||
|
handleSelect(languageTag);
|
||||||
|
})}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
onSelect(languageTag);
|
handleSelect(languageTag);
|
||||||
setIsDropDownOpen(false);
|
|
||||||
setSearchInputValue('');
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div className={style.languageName}>{uiLanguageNameMapping[languageTag]}</div>
|
<div className={style.languageName}>{uiLanguageNameMapping[languageTag]}</div>
|
||||||
|
|
|
@ -2,6 +2,8 @@ import { languages, LanguageTag } from '@logto/language-kit';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import { useEffect, useRef } from 'react';
|
import { useEffect, useRef } from 'react';
|
||||||
|
|
||||||
|
import { onKeyDownHandler } from '@/utilities/a11y';
|
||||||
|
|
||||||
import * as style from './LanguageItem.module.scss';
|
import * as style from './LanguageItem.module.scss';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
|
@ -19,18 +21,22 @@ const LanguageItem = ({ languageTag, isSelected, onClick }: Props) => {
|
||||||
}
|
}
|
||||||
}, [isSelected]);
|
}, [isSelected]);
|
||||||
|
|
||||||
return (
|
const handleSelect = () => {
|
||||||
// TODO: @yijun
|
|
||||||
// eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions
|
|
||||||
<div
|
|
||||||
ref={itemRef}
|
|
||||||
className={classNames(style.languageItem, isSelected && style.selected)}
|
|
||||||
onClick={() => {
|
|
||||||
if (isSelected) {
|
if (isSelected) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
onClick();
|
onClick();
|
||||||
}}
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
ref={itemRef}
|
||||||
|
role="tab"
|
||||||
|
tabIndex={0}
|
||||||
|
aria-selected={isSelected}
|
||||||
|
className={classNames(style.languageItem, isSelected && style.selected)}
|
||||||
|
onClick={handleSelect}
|
||||||
|
onKeyDown={onKeyDownHandler(handleSelect)}
|
||||||
>
|
>
|
||||||
<div className={style.languageName}>{languages[languageTag]}</div>
|
<div className={style.languageName}>{languages[languageTag]}</div>
|
||||||
<div className={style.languageTag}>{languageTag}</div>
|
<div className={style.languageTag}>{languageTag}</div>
|
||||||
|
|
Loading…
Add table
Reference in a new issue