mirror of
https://github.com/elastic/kibana.git
synced 2025-06-27 18:51:07 -04:00
[A11y] Add labels to control inputs (#221639)
## Summary Closes #183202. Closes #220687. This adds aria-labels to the number fields on the range slider control. <img width="704" alt="Screenshot 2025-05-27 at 8 10 38 AM" src="https://github.com/user-attachments/assets/ffeb1b98-6765-41ab-abd3-bff2ce176cda" /> <img width="413" alt="Screenshot 2025-05-27 at 8 04 59 AM" src="https://github.com/user-attachments/assets/e899b1f9-6290-463f-9213-2e0a456fa677" /> This also adds an aria-label to the search filter at the top of the options list popover. <img width="2559" alt="Screenshot 2025-06-02 at 7 23 53 AM" src="https://github.com/user-attachments/assets/47e870dc-55c2-40bd-b461-a16022691810" /> ### Checklist Check the PR satisfies following conditions. Reviewers should verify this PR satisfies this list as well. - [ ] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md) - [ ] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [ ] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [ ] If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the [docker list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker) - [ ] This was checked for breaking HTTP API changes, and any breaking changes have been approved by the breaking-change committee. The `release_note:breaking` label should be applied in these situations. - [ ] [Flaky Test Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was used on any tests changed - [ ] The PR description includes the appropriate Release Notes section, and the correct `release_note:*` label is applied per the [guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) ### Identify risks Does this PR introduce any risks? For example, consider risks like hard to test bugs, performance regression, potential of data loss. Describe the risk, its severity, and mitigation for each identified risk. Invite stakeholders and evaluate how to proceed before merging. - [ ] [See some risk examples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx) - [ ] ... --------- Co-authored-by: Marta Bondyra <4283304+mbondyra@users.noreply.github.com>
This commit is contained in:
parent
1c76710f67
commit
f7dad16597
4 changed files with 60 additions and 24 deletions
|
@ -98,6 +98,7 @@ export const ControlPanel = <ApiType extends DefaultControlApi = DefaultControlA
|
|||
const isEditable = viewMode === 'edit';
|
||||
const controlWidth = width ?? DEFAULT_CONTROL_WIDTH;
|
||||
const controlGrow = grow ?? DEFAULT_CONTROL_GROW;
|
||||
const controlLabel = isTwoLine ? panelTitle || defaultPanelTitle || '...' : undefined;
|
||||
const hasRoundedBorders = !api?.CustomPrependComponent && !isEditable && isTwoLine;
|
||||
const shouldHideComponent = Boolean(blockingError);
|
||||
|
||||
|
@ -135,7 +136,9 @@ export const ControlPanel = <ApiType extends DefaultControlApi = DefaultControlA
|
|||
<EuiFormRow
|
||||
data-test-subj="control-frame-title"
|
||||
fullWidth
|
||||
label={isTwoLine ? panelTitle || defaultPanelTitle || '...' : undefined}
|
||||
label={controlLabel}
|
||||
id={`control-title-${uuid}`}
|
||||
aria-label={`Control for ${controlLabel}`}
|
||||
>
|
||||
<EuiFormControlLayout
|
||||
fullWidth
|
||||
|
|
|
@ -23,31 +23,33 @@ import { RangeSliderStrings } from '../range_slider_strings';
|
|||
import { rangeSliderControlStyles } from './range_slider.styles';
|
||||
|
||||
interface Props {
|
||||
fieldFormatter?: (value: string) => string;
|
||||
compressed: boolean;
|
||||
controlPanelClassName?: string;
|
||||
isInvalid: boolean;
|
||||
isLoading: boolean;
|
||||
fieldName: string;
|
||||
max: number | undefined;
|
||||
min: number | undefined;
|
||||
onChange: (value: RangeValue | undefined) => void;
|
||||
step: number;
|
||||
value: RangeValue | undefined;
|
||||
uuid: string;
|
||||
controlPanelClassName?: string;
|
||||
compressed: boolean;
|
||||
value: RangeValue | undefined;
|
||||
fieldFormatter?: (value: string) => string;
|
||||
onChange: (value: RangeValue | undefined) => void;
|
||||
}
|
||||
|
||||
export const RangeSliderControl: FC<Props> = ({
|
||||
fieldFormatter,
|
||||
compressed,
|
||||
controlPanelClassName,
|
||||
isInvalid,
|
||||
isLoading,
|
||||
fieldName,
|
||||
max,
|
||||
min,
|
||||
onChange,
|
||||
step,
|
||||
value,
|
||||
uuid,
|
||||
controlPanelClassName,
|
||||
compressed,
|
||||
value,
|
||||
fieldFormatter,
|
||||
onChange,
|
||||
}: Props) => {
|
||||
const rangeSliderRef = useRef<EuiDualRangeProps | null>(null);
|
||||
|
||||
|
@ -141,10 +143,14 @@ export const RangeSliderControl: FC<Props> = ({
|
|||
inputValue,
|
||||
testSubj,
|
||||
placeholder,
|
||||
ariaLabel,
|
||||
id,
|
||||
}: {
|
||||
inputValue: string;
|
||||
testSubj: string;
|
||||
placeholder: string;
|
||||
ariaLabel: string;
|
||||
id: string;
|
||||
}) => {
|
||||
return {
|
||||
isInvalid: undefined, // disabling this prop to handle our own validation styling
|
||||
|
@ -155,9 +161,12 @@ export const RangeSliderControl: FC<Props> = ({
|
|||
isInvalid ? styles.fieldNumbers.invalid : styles.fieldNumbers.valid,
|
||||
],
|
||||
className: 'rangeSliderAnchor__fieldNumber',
|
||||
'data-test-subj': `rangeSlider__${testSubj}`,
|
||||
value: inputValue === placeholder ? '' : inputValue,
|
||||
title: !isInvalid && step ? '' : undefined, // overwrites native number input validation error when the value falls between two steps
|
||||
'data-test-subj': `rangeSlider__${testSubj}`,
|
||||
'aria-label': ariaLabel,
|
||||
'aria-labelledby': `control-title-${id}`,
|
||||
id: `controls-range-slider-${id}`,
|
||||
};
|
||||
},
|
||||
[isInvalid, step, styles]
|
||||
|
@ -168,16 +177,20 @@ export const RangeSliderControl: FC<Props> = ({
|
|||
inputValue: displayedValue[0],
|
||||
testSubj: 'lowerBoundFieldNumber',
|
||||
placeholder: String(min ?? -Infinity),
|
||||
ariaLabel: RangeSliderStrings.control.getLowerBoundAriaLabel(fieldName),
|
||||
id: uuid,
|
||||
});
|
||||
}, [getCommonInputProps, min, displayedValue]);
|
||||
}, [getCommonInputProps, displayedValue, min, fieldName, uuid]);
|
||||
|
||||
const maxInputProps = useMemo(() => {
|
||||
return getCommonInputProps({
|
||||
inputValue: displayedValue[1],
|
||||
testSubj: 'upperBoundFieldNumber',
|
||||
placeholder: String(max ?? Infinity),
|
||||
ariaLabel: RangeSliderStrings.control.getUpperBoundAriaLabel(fieldName),
|
||||
id: uuid,
|
||||
});
|
||||
}, [getCommonInputProps, max, displayedValue]);
|
||||
}, [getCommonInputProps, displayedValue, max, fieldName, uuid]);
|
||||
|
||||
return (
|
||||
<span
|
||||
|
|
|
@ -236,16 +236,25 @@ export const getRangesliderControlFactory = (): DataControlFactory<
|
|||
return {
|
||||
api,
|
||||
Component: ({ className: controlPanelClassName }) => {
|
||||
const [dataLoading, fieldFormatter, max, min, selectionHasNoResults, step, value] =
|
||||
useBatchedPublishingSubjects(
|
||||
dataLoading$,
|
||||
dataControlManager.api.fieldFormatter,
|
||||
max$,
|
||||
min$,
|
||||
selectionHasNoResults$,
|
||||
step$,
|
||||
selections.value$
|
||||
);
|
||||
const [
|
||||
dataLoading,
|
||||
fieldFormatter,
|
||||
max,
|
||||
min,
|
||||
selectionHasNoResults,
|
||||
step,
|
||||
value,
|
||||
fieldName,
|
||||
] = useBatchedPublishingSubjects(
|
||||
dataLoading$,
|
||||
dataControlManager.api.fieldFormatter,
|
||||
max$,
|
||||
min$,
|
||||
selectionHasNoResults$,
|
||||
step$,
|
||||
selections.value$,
|
||||
dataControlManager.api.fieldName$
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
|
@ -260,6 +269,7 @@ export const getRangesliderControlFactory = (): DataControlFactory<
|
|||
return (
|
||||
<RangeSliderControl
|
||||
controlPanelClassName={controlPanelClassName}
|
||||
fieldName={fieldName}
|
||||
fieldFormatter={fieldFormatter}
|
||||
isInvalid={Boolean(value) && selectionHasNoResults}
|
||||
isLoading={typeof dataLoading === 'boolean' ? dataLoading : false}
|
||||
|
|
|
@ -19,6 +19,16 @@ export const RangeSliderStrings = {
|
|||
i18n.translate('controls.rangeSlider.control.invalidSelectionWarningLabel', {
|
||||
defaultMessage: 'Selected range returns no results.',
|
||||
}),
|
||||
getLowerBoundAriaLabel: (fieldName: string) =>
|
||||
i18n.translate('controls.rangeSlider.control.lowerBoundAriaLabel', {
|
||||
defaultMessage: 'Range slider lower bound for {fieldName}',
|
||||
values: { fieldName },
|
||||
}),
|
||||
getUpperBoundAriaLabel: (fieldName: string) =>
|
||||
i18n.translate('controls.rangeSlider.control.lowerBoundAriaLabel', {
|
||||
defaultMessage: 'Range slider upper bound for {fieldName}',
|
||||
values: { fieldName },
|
||||
}),
|
||||
},
|
||||
editor: {
|
||||
getStepTitle: () =>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue