Grafana UI: fix ColorSwatch aria-label (#74280)

This commit is contained in:
Laura Fernández 2023-09-01 17:52:55 +02:00 committed by GitHub
parent d8d2f890b5
commit f4ad247df2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -28,16 +28,15 @@ export const ColorSwatch = React.forwardRef<HTMLDivElement, Props>(
const theme = useTheme2();
const { isFocusVisible, focusProps } = useFocusRing();
const styles = getStyles(theme, variant, color, isFocusVisible, isSelected);
const hasLabel = !label;
const hasLabel = !!label;
const colorLabel = ariaLabel || label;
return (
<div ref={ref} className={styles.wrapper} data-testid={selectors.components.ColorSwatch.name} {...otherProps}>
{hasLabel && <span className={styles.label}>{label}</span>}
<button
className={styles.swatch}
{...focusProps}
aria-label={hasLabel ? `${colorLabel} color` : 'Pick a color'}
aria-label={colorLabel ? `${colorLabel} color` : 'Pick a color'}
type="button"
/>
</div>