Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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
Expand All @@ -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]
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: () =>
Expand Down