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
20 changes: 15 additions & 5 deletions packages/@react-aria/numberfield/src/useNumberField.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ interface NumberFieldAria {
/** Props for the increment button, to be passed to [useButton](useButton.html). */
incrementButtonProps: AriaButtonProps,
/** Props for the decrement button, to be passed to [useButton](useButton.html). */
decrementButtonProps: AriaButtonProps
decrementButtonProps: AriaButtonProps,
/** Props for the number field's description element. */
descriptionProps: HTMLAttributes<HTMLElement>,
/** Props for the number field's error message element. */
errorMessageProps: HTMLAttributes<HTMLElement>
}

/**
Expand All @@ -70,7 +74,9 @@ export function useNumberField(props: AriaNumberFieldProps, state: NumberFieldSt
onFocus,
onFocusChange,
onKeyDown,
onKeyUp
onKeyUp,
description,
errorMessage
} = props;

let {
Expand Down Expand Up @@ -166,7 +172,7 @@ export function useNumberField(props: AriaNumberFieldProps, state: NumberFieldSt
state.setInputValue(value);
};

let {labelProps, inputProps: textFieldProps} = useFormattedTextField({
let {labelProps, inputProps: textFieldProps, descriptionProps, errorMessageProps} = useFormattedTextField({
label,
autoFocus,
isDisabled,
Expand All @@ -185,7 +191,9 @@ export function useNumberField(props: AriaNumberFieldProps, state: NumberFieldSt
onFocus,
onFocusChange,
onKeyDown,
onKeyUp
onKeyUp,
description,
errorMessage
}, state, inputRef);

let inputProps = mergeProps(
Expand Down Expand Up @@ -274,6 +282,8 @@ export function useNumberField(props: AriaNumberFieldProps, state: NumberFieldSt
labelProps,
inputProps,
incrementButtonProps,
decrementButtonProps
decrementButtonProps,
errorMessageProps,
descriptionProps
};
}
4 changes: 2 additions & 2 deletions packages/@react-aria/searchfield/src/useSearchField.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ interface SearchFieldAria {
inputProps: InputHTMLAttributes<HTMLInputElement | HTMLTextAreaElement>,
/** Props for the clear button. */
clearButtonProps: AriaButtonProps,
/** Props for the description element. */
/** Props for the searchfield's description element. */
descriptionProps: HTMLAttributes<HTMLElement>,
/** Props for the error message element. */
/** Props for the searchfield's error message element. */
errorMessageProps: HTMLAttributes<HTMLElement>
}

Expand Down
4 changes: 2 additions & 2 deletions packages/@react-aria/select/src/useSelect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ interface SelectAria {
/** Props for the popup. */
menuProps: AriaListBoxOptions<unknown>,

/** Props for the description element. */
/** Props for the select's description element. */
descriptionProps: HTMLAttributes<HTMLElement>,

/** Props for the error message element. */
/** Props for the select's error message element. */
errorMessageProps: HTMLAttributes<HTMLElement>
}

Expand Down
6 changes: 5 additions & 1 deletion packages/@react-spectrum/numberfield/src/NumberField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ function NumberField(props: SpectrumNumberFieldProps, ref: FocusableRef<HTMLElem
labelProps,
inputProps,
incrementButtonProps,
decrementButtonProps
decrementButtonProps,
descriptionProps,
errorMessageProps
} = useNumberField(props, state, inputRef);
let isMobile = provider.scale === 'large';
let showStepper = !hideStepper;
Expand All @@ -77,6 +79,8 @@ function NumberField(props: SpectrumNumberFieldProps, ref: FocusableRef<HTMLElem
return (
<Field
{...props as Omit<SpectrumNumberFieldProps, 'onChange'>}
descriptionProps={descriptionProps}
errorMessageProps={errorMessageProps}
labelProps={labelProps}
ref={domRef}
wrapperClassName={classNames(
Expand Down
21 changes: 21 additions & 0 deletions packages/@react-spectrum/numberfield/test/NumberField.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1614,6 +1614,27 @@ describe('NumberField', function () {
expect(decrementButton).not.toHaveAttribute('id');
expect(decrementButton).not.toHaveAttribute('aria-labelledby');
});

it('error message', () => {
let {textField, root} = renderNumberField({
label: 'Width',
errorMessage: 'This is a error.',
validationState: 'invalid'
});

let errorText = within(root).getByText('This is a error.');
expect(textField).toHaveAttribute('aria-describedby', errorText.id);
});

it('description', () => {
let {textField, root} = renderNumberField({
label: 'Width',
description: 'This is a description.'
});

let description = within(root).getByText('This is a description.');
expect(textField).toHaveAttribute('aria-describedby', description.id);
});
});

it.each`
Expand Down
3 changes: 2 additions & 1 deletion packages/@react-types/numberfield/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
AriaLabelingProps,
DOMProps,
FocusableProps,
HelpTextProps,
InputBase, LabelableProps,
RangeInputBase, SpectrumLabelableProps,
StyleProps,
Expand All @@ -22,7 +23,7 @@ import {
ValueBase
} from '@react-types/shared';

export interface NumberFieldProps extends InputBase, Validation, FocusableProps, TextInputBase, ValueBase<number>, RangeInputBase<number>, LabelableProps {
export interface NumberFieldProps extends InputBase, Validation, FocusableProps, TextInputBase, ValueBase<number>, RangeInputBase<number>, LabelableProps, HelpTextProps {
/**
* Formatting options for the value displayed in the number field.
* This also affects what characters are allowed to be typed by the user.
Expand Down