Skip to content
Open
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
18 changes: 16 additions & 2 deletions src/InputNumber.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ export interface InputNumberProps<T extends ValueType = ValueType>
// Customize handler node
upHandler?: React.ReactNode;
downHandler?: React.ReactNode;
upAriaLabel?: string;
downAriaLabel?: string;
keyboard?: boolean;
changeOnWheel?: boolean;

Expand Down Expand Up @@ -174,6 +176,8 @@ const InputNumber = React.forwardRef<InputNumberRef, InputNumberProps>((props, r
readOnly,
upHandler,
downHandler,
upAriaLabel,
downAriaLabel,
keyboard,
changeOnWheel = false,
controls = true,
Expand Down Expand Up @@ -715,13 +719,23 @@ const InputNumber = React.forwardRef<InputNumberRef, InputNumberProps>((props, r
};

const upNode = (
<StepHandler {...sharedHandlerProps} action="up" disabled={upDisabled}>
<StepHandler
{...sharedHandlerProps}
action="up"
disabled={upDisabled}
aria-label={upAriaLabel}
>
{upHandler}
</StepHandler>
);

const downNode = (
<StepHandler {...sharedHandlerProps} action="down" disabled={downDisabled}>
<StepHandler
{...sharedHandlerProps}
action="down"
disabled={downDisabled}
aria-label={downAriaLabel}
>
{downHandler}
</StepHandler>
);
Expand Down
4 changes: 3 additions & 1 deletion src/StepHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface StepHandlerProps {
className?: string;
style?: React.CSSProperties;
onStep: (up: boolean, emitter: 'handler' | 'keyboard' | 'wheel') => void;
'aria-label'?: string;
}

export default function StepHandler({
Expand All @@ -31,6 +32,7 @@ export default function StepHandler({
className,
style,
onStep,
'aria-label': ariaLabel,
}: StepHandlerProps) {
// ======================== MISC ========================
const isUpAction = action === 'up';
Expand Down Expand Up @@ -99,7 +101,7 @@ export default function StepHandler({
onMouseDown={(e) => {
onStepMouseDown(e);
}}
aria-label={isUpAction ? 'Increase Value' : 'Decrease Value'}
aria-label={ariaLabel ?? (isUpAction ? 'Increase Value' : 'Decrease Value')}
aria-disabled={disabled}
className={mergedClassName}
style={style}
Expand Down
11 changes: 11 additions & 0 deletions tests/renderability.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,14 @@ it('renders zero step handlers and keeps them interactive', () => {
fireEvent.mouseUp(down);
expect(onChange).toHaveBeenLastCalledWith(2);
});

it('supports custom accessible names for step handlers via upAriaLabel and downAriaLabel', () => {
const { getByRole } = render(
<InputNumber
upAriaLabel="Augmenter la valeur"
downAriaLabel="Diminuer la valeur"
/>,
);
expect(getByRole('button', { name: 'Augmenter la valeur' })).toBeTruthy();
expect(getByRole('button', { name: 'Diminuer la valeur' })).toBeTruthy();
});