Skip to content

Commit

Permalink
Merge pull request #1 from Xelsing/main
Browse files Browse the repository at this point in the history
refactor: add aria
  • Loading branch information
iPagar authored Feb 6, 2024
2 parents 2a96af8 + a7bbb72 commit c3bb218
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
"jsx-a11y/no-autofocus": "off",
"react/button-has-type": "off",
"jsx-a11y/no-noninteractive-element-interactions": "off",
"no-shadow": "off"
"no-shadow": "off",
"jsx-a11y/role-has-required-aria-props": "off"
},
"settings": {
"import/resolver": {
Expand Down
2 changes: 2 additions & 0 deletions src/phone-input/phone-input-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export function PhoneInputItem(
<li
{...props}
{...itemProps}
aria-controls={country}
className={clsx(styles.countrySelectItem, className)}
onClick={handleSelect}
onKeyDown={handleKeyDown}
Expand All @@ -62,6 +63,7 @@ export function usePhoneInputItem(props: UsePhoneInputItemProps) {
return {
getListItemProps: useCallback(
(itemProps: { value: string }) => ({
'aria-controls': itemProps.value,
'aria-selected': selected === itemProps.value,
role: 'option' as const,
}),
Expand Down
10 changes: 9 additions & 1 deletion src/phone-input/phone-input-trigger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ export function PhoneInputTrigger(
return (
<button
{...props}
aria-expanded={isDialogOpen}
aria-haspopup="listbox"
aria-label="Country selector"
className={clsx(styles.phoneInputTrigger, className)}
data-open={isDialogOpen}
onClick={handleTogglePopover}
Expand All @@ -31,17 +34,22 @@ export function PhoneInputTrigger(
});
}
}}
// eslint-disable-next-line no-use-before-define
role="combobox"
type="button"
>
{children}
</button>
);
}

export function usePhoneInputTrigger() {
export function usePhoneInputTrigger(props: { open: boolean }) {
return {
triggerProps: {
'aria-expanded': props.open,
'aria-haspopup': 'listbox',
'aria-label': 'Select country',
role: 'combobox',
type: 'button',
} as const,
};
Expand Down
4 changes: 4 additions & 0 deletions src/phone-input/phone-input.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
&Trigger {
background: none;
border: none;

& * {
pointer-events: none;
}
}

&Dialog {
Expand Down
4 changes: 3 additions & 1 deletion src/phone-input/phone-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ export function usePhone(
const { getListItemProps } = usePhoneInputItem({
selected: state.country,
});
const { triggerProps } = usePhoneInputTrigger();
const { triggerProps } = usePhoneInputTrigger({
open: props.isDialogOpen,
});
const { phoneInputDialogProps } = usePhoneInputDialog({
open: props.isDialogOpen,
});
Expand Down
7 changes: 6 additions & 1 deletion stories/phone-input.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,10 @@ export function StyledWithAnimation() {
>
{({ open }) => (
<>
<PhoneInput.Trigger className={styles.countrySelect}>
<PhoneInput.Trigger
className={styles.countrySelect}
id="country-selector"
>
<CountryFlag className={styles.countryFlag} country={country} />
<div className={styles.countryIcon}>
<svg
Expand Down Expand Up @@ -308,8 +311,10 @@ export function StyledWithAnimation() {
</div>
{open && (
<input
aria-labelledby="country-selector search-input"
autoFocus
className={styles.countrySelectSearchInput}
id="search-input"
onChange={(e) => setSearch(e.target.value)}
placeholder="Search"
type="text"
Expand Down

0 comments on commit c3bb218

Please sign in to comment.