From 019ab0c3e8490ccfa9d37869de128fa10458553b Mon Sep 17 00:00:00 2001 From: Serhii Frolov Date: Wed, 4 Oct 2023 15:34:17 +0200 Subject: [PATCH] feat(ui): set role and title at Icon and Loader --- packages/ui/src/Icon.tsx | 16 ++++++++++++++-- packages/ui/src/IconButton.tsx | 8 ++++++-- packages/ui/src/Loader.tsx | 9 +++++++-- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/packages/ui/src/Icon.tsx b/packages/ui/src/Icon.tsx index 6ec5c6cc9..ef123c8da 100644 --- a/packages/ui/src/Icon.tsx +++ b/packages/ui/src/Icon.tsx @@ -38,11 +38,23 @@ export type IconProps = { className?: string containerClassName?: string bold?: boolean + role?: string } & IconAriaProps export const Icon = forwardRef( ( - { color, icon: IconElement, ariaLabel, ariaLabelledBy, ariaHidden, className, containerClassName, size = 'medium', bold = false }, + { + color, + icon: IconElement, + ariaLabel, + ariaLabelledBy, + ariaHidden, + className, + containerClassName, + size = 'medium', + bold = false, + role = 'img', + }, ref, ) => { const iconStroke = bold ? styleConsts.iconStrokeWidthBold : styleConsts.iconStrokeWidth @@ -69,7 +81,7 @@ export const Icon = forwardRef( return (
- +
) }, diff --git a/packages/ui/src/IconButton.tsx b/packages/ui/src/IconButton.tsx index 6c9c11a2f..a811eb371 100644 --- a/packages/ui/src/IconButton.tsx +++ b/packages/ui/src/IconButton.tsx @@ -18,6 +18,8 @@ type IconButtonCommonProps = { icon: FeatherIcon iconClassName?: string iconColor?: string + iconRole?: string + loaderRole?: string kind?: IconButtonKind size?: IconProps['size'] padding?: 'normal' @@ -66,6 +68,8 @@ export const IconButton = forwardRef( icon, iconClassName, iconColor, + iconRole, + loaderRole, className, size, kind = 'transparent', @@ -121,8 +125,8 @@ export const IconButton = forwardRef( {...rest} > - {loading && } - {!loading && } + {loading && } + {!loading && } )} diff --git a/packages/ui/src/Loader.tsx b/packages/ui/src/Loader.tsx index afba34ed4..525a487d4 100644 --- a/packages/ui/src/Loader.tsx +++ b/packages/ui/src/Loader.tsx @@ -10,14 +10,17 @@ export type LoaderProps = { size?: IconSize kind?: 'primary' | 'contrast' | 'inherit' children?: never + title?: string + role?: string } & Pick, 'aria-hidden'> -export const Loader: FC = ({ className, size = 'medium', kind = 'inherit', ...props }) => ( +export const Loader: FC = ({ className, size = 'medium', kind = 'inherit', role = 'img', title, ...props }) => ( // https://github.com/feathericons/feather/blob/a718a7e9c39447202f703783336e8ba1c8e32405/icons/loader.svg#L1 // We cannot use it directly as it has `line` elements not in a sequential order // And we need the sequential order to easily calculate animation delay = ({ className, size = 'medium', kind = 'in strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" - aria-label="Loader icon" + aria-label={title ? title : 'Loader icon'} + aria-labelledby="loader-title" {...props} > + {title && {title}}