Skip to content

Commit 0ba87f8

Browse files
committed
fix(EuiColorPicker): change open/close labels to be used via
1 parent 8f5bbed commit 0ba87f8

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

packages/eui/src/components/color_picker/color_picker.stories.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import React, { FunctionComponent, useState, useEffect } from 'react';
1010
import type { Meta, StoryObj } from '@storybook/react';
1111
import { enableFunctionToggleControls } from '../../../.storybook/utils';
1212

13-
import { euiPaletteColorBlind } from '../..//services';
13+
import { euiPaletteColorBlind } from '../../services';
14+
import { EuiFormRow } from '../form';
1415
import { EuiColorPicker, EuiColorPickerProps } from './color_picker';
1516

1617
const meta: Meta<EuiColorPickerProps> = {
@@ -45,6 +46,21 @@ export const Playground: Story = {
4546
render: (args) => <StatefulColorPicker {...args} />,
4647
};
4748

49+
export const InFormRow: Story = {
50+
name: 'In FormRow',
51+
parameters: {
52+
loki: {
53+
skip: true,
54+
},
55+
},
56+
...Playground,
57+
render: (args) => (
58+
<EuiFormRow label="Pick a color">
59+
<StatefulColorPicker {...args} />
60+
</EuiFormRow>
61+
),
62+
};
63+
4864
export const InlineWithAllElements: Story = {
4965
tags: ['vrt-only'],
5066
args: {

packages/eui/src/components/color_picker/color_picker.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
useEuiMemoizedStyles,
2424
keys,
2525
useEuiPaletteColorBlind,
26+
useGeneratedHtmlId,
2627
} from '../../services';
2728
import { CommonProps } from '../common';
2829
import {
@@ -242,6 +243,11 @@ export const EuiColorPicker: FunctionComponent<EuiColorPickerProps> = ({
242243
]
243244
);
244245

246+
const ariaDescribedById = useGeneratedHtmlId({
247+
prefix: 'colorPicker',
248+
suffix: 'ariaDescribedby',
249+
});
250+
245251
const defaultSwatches = useEuiPaletteColorBlind();
246252
const swatches = _swatches ?? defaultSwatches;
247253

@@ -562,6 +568,8 @@ export const EuiColorPicker: FunctionComponent<EuiColorPickerProps> = ({
562568
</>
563569
);
564570

571+
console.log(ariaDescribedById);
572+
565573
let buttonOrInput;
566574
if (button) {
567575
buttonOrInput = cloneElement(button, {
@@ -621,9 +629,14 @@ export const EuiColorPicker: FunctionComponent<EuiColorPickerProps> = ({
621629
fullWidth={fullWidth}
622630
autoComplete="off"
623631
data-test-subj={testSubjAnchor}
624-
aria-label={isColorSelectorShown ? openLabel : closeLabel}
632+
aria-describedby={ariaDescribedById}
625633
controlOnly // Don't need two EuiFormControlwrappers
626634
/>
635+
<EuiScreenReaderOnly>
636+
<span id={ariaDescribedById}>
637+
{isColorSelectorShown ? openLabel : closeLabel}
638+
</span>
639+
</EuiScreenReaderOnly>
627640
</EuiFormControlLayout>
628641
);
629642
}

0 commit comments

Comments
 (0)