Skip to content

Commit e02d205

Browse files
authored
Replace validationState with isInvalid (#4972)
1 parent 2f32c05 commit e02d205

File tree

118 files changed

+669
-434
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+669
-434
lines changed

packages/@react-aria/calendar/src/useCalendarBase.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export function useCalendarBase(props: CalendarPropsBase & DOMProps & AriaLabeli
5959
// handle an update to the caption that describes the currently selected range, to announce the new value
6060
}, [selectedDateDescription]);
6161

62-
let errorMessageId = useSlotId([Boolean(props.errorMessage), props.validationState]);
62+
let errorMessageId = useSlotId([Boolean(props.errorMessage), props.isInvalid, props.validationState]);
6363

6464
// Pass the label to the child grid elements.
6565
hookData.set(state, {

packages/@react-aria/calendar/src/useCalendarCell.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export function useCalendarCell(props: AriaCalendarCellProps, state: CalendarSta
8989
isDisabled = isDisabled || state.isCellDisabled(date);
9090
let isUnavailable = state.isCellUnavailable(date);
9191
let isSelectable = !isDisabled && !isUnavailable;
92-
let isInvalid = state.validationState === 'invalid' && (
92+
let isInvalid = state.isValueInvalid && (
9393
'highlightedRange' in state
9494
? !state.anchorDate && state.highlightedRange && date.compare(state.highlightedRange.start) >= 0 && date.compare(state.highlightedRange.end) <= 0
9595
: state.value && isSameDay(state.value, date)

packages/@react-aria/checkbox/docs/useCheckboxGroup.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ import {useCheckboxGroupState} from '@react-stately/checkbox';
105105
let CheckboxGroupContext = React.createContext(null);
106106

107107
function CheckboxGroup(props) {
108-
let {children, label, description, errorMessage, validationState} = props;
108+
let {children, label, description, errorMessage} = props;
109109
let state = useCheckboxGroupState(props);
110110
let {groupProps, labelProps, descriptionProps, errorMessageProps} = useCheckboxGroup(props, state);
111111

@@ -116,7 +116,7 @@ function CheckboxGroup(props) {
116116
{children}
117117
</CheckboxGroupContext.Provider>
118118
{description && <div {...descriptionProps} style={{fontSize: 12}}>{description}</div>}
119-
{errorMessage && validationState === 'invalid' &&
119+
{errorMessage && state.isInvalid &&
120120
<div {...errorMessageProps} style={{color: 'red', fontSize: 12}}>{errorMessage}</div>
121121
}
122122
</div>
@@ -214,11 +214,11 @@ The `description` prop can be used to associate additional help text with a chec
214214

215215
### Error message
216216

217-
The `errorMessage` prop can be used to help the user fix a validation error. It should be combined with the `validationState` prop to
217+
The `errorMessage` prop can be used to help the user fix a validation error. It should be combined with the `isInvalid` prop to
218218
semantically mark the checkbox group as invalid for assistive technologies.
219219

220220
```tsx example
221-
<CheckboxGroup label="Favorite sports" errorMessage="Invalid selection of sports." validationState="invalid">
221+
<CheckboxGroup label="Favorite sports" errorMessage="Invalid selection of sports." isInvalid>
222222
<Checkbox value="soccer">Soccer</Checkbox>
223223
<Checkbox value="baseball">Baseball</Checkbox>
224224
<Checkbox value="basketball">Basketball</Checkbox>

packages/@react-aria/checkbox/src/useCheckbox.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ export interface CheckboxAria {
2525
/** Whether the checkbox is disabled. */
2626
isDisabled: boolean,
2727
/** Whether the checkbox is read only. */
28-
isReadOnly: boolean
28+
isReadOnly: boolean,
29+
/** Whether the checkbox is invalid. */
30+
isInvalid: boolean
2931
}
3032

3133
/**
@@ -37,7 +39,7 @@ export interface CheckboxAria {
3739
* @param inputRef - A ref for the HTML input element.
3840
*/
3941
export function useCheckbox(props: AriaCheckboxProps, state: ToggleState, inputRef: RefObject<HTMLInputElement>): CheckboxAria {
40-
let {inputProps, isSelected, isPressed, isDisabled, isReadOnly} = useToggle(props, state, inputRef);
42+
let {inputProps, isSelected, isPressed, isDisabled, isReadOnly, isInvalid} = useToggle(props, state, inputRef);
4143

4244
let {isIndeterminate} = props;
4345
useEffect(() => {
@@ -56,6 +58,7 @@ export function useCheckbox(props: AriaCheckboxProps, state: ToggleState, inputR
5658
isSelected,
5759
isPressed,
5860
isDisabled,
59-
isReadOnly
61+
isReadOnly,
62+
isInvalid
6063
};
6164
}

packages/@react-aria/checkbox/src/useCheckboxGroupItem.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export function useCheckboxGroupItem(props: AriaCheckboxGroupItemProps, state: C
5454
...res.inputProps,
5555
'aria-describedby': [
5656
props['aria-describedby'],
57-
state.validationState === 'invalid' ? checkboxGroupErrorMessageIds.get(state) : null,
57+
state.isInvalid ? checkboxGroupErrorMessageIds.get(state) : null,
5858
checkboxGroupDescriptionIds.get(state)
5959
].filter(Boolean).join(' ') || undefined
6060
}

packages/@react-aria/color/test/useColorField.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ describe('useColorField', function () {
7474
});
7575

7676
it('should return prop for invalid', function () {
77-
let {inputProps} = renderColorFieldHook({validationState: 'invalid'});
77+
let {inputProps} = renderColorFieldHook({isInvalid: true});
7878
expect(inputProps['aria-invalid']).toBe(true);
7979
});
8080

packages/@react-aria/datepicker/docs/useDateField.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export function DateField(props) {
117117
{state.segments.map((segment, i) =>
118118
<DateSegment key={i} segment={segment} state={state} />
119119
)}
120-
{state.validationState === 'invalid' &&
120+
{state.isInvalid &&
121121
<span aria-hidden="true">🚫</span>
122122
}
123123
</div>

packages/@react-aria/datepicker/docs/useDatePicker.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ function DateField(props) {
166166
{state.segments.map((segment, i) =>
167167
<DateSegment key={i} segment={segment} state={state} />
168168
)}
169-
{state.validationState === 'invalid' &&
169+
{state.isInvalid &&
170170
<span aria-hidden="true">🚫</span>
171171
}
172172
</div>

packages/@react-aria/datepicker/docs/useDateRangePicker.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ function DateRangePicker(props) {
104104
<DateField {...startFieldProps} />
105105
<span style={{padding: '0 4px'}}>–</span>
106106
<DateField {...endFieldProps} />
107-
{state.validationState === 'invalid' &&
107+
{state.isInvalid &&
108108
<span aria-hidden="true">🚫</span>
109109
}
110110
</div>
@@ -674,9 +674,9 @@ import {today} from '@internationalized/date';
674674

675675
`useDateRangePicker` supports marking certain dates as _unavailable_. These dates remain focusable with the keyboard in the calendar so that navigation is consistent, but cannot be selected by the user. The `isDateUnavailable` prop accepts a callback that is called to evaluate whether each visible date is unavailable.
676676

677-
Note that by default, users may not select non-contiguous ranges, i.e. ranges that contain unavailable dates within them. Once a start date is selected in the calendar, enabled dates will be restricted to subsequent dates until an unavailable date is hit. While this is handled automatically in the calendar, additional validation logic must be provided to ensure an invalid state is displayed in the date field. This can be achieved using the `validationState` prop. See [below](#non-contiguous-ranges) for an example of how to allow non-contiguous ranges.
677+
Note that by default, users may not select non-contiguous ranges, i.e. ranges that contain unavailable dates within them. Once a start date is selected in the calendar, enabled dates will be restricted to subsequent dates until an unavailable date is hit. While this is handled automatically in the calendar, additional validation logic must be provided to ensure an invalid state is displayed in the date field. This can be achieved using the `isInvalid` prop. See [below](#non-contiguous-ranges) for an example of how to allow non-contiguous ranges.
678678

679-
This example includes multiple unavailable date ranges, e.g. dates when a rental house is not available. The `minValue` prop is also used to prevent selecting dates before today. The `validationState` prop is used to mark selected date ranges with unavailable dates in the middle as invalid.
679+
This example includes multiple unavailable date ranges, e.g. dates when a rental house is not available. The `minValue` prop is also used to prevent selecting dates before today. The `isInvalid` prop is used to mark selected date ranges with unavailable dates in the middle as invalid.
680680

681681
```tsx example
682682
import {today} from '@internationalized/date';
@@ -700,7 +700,7 @@ function Example() {
700700
isDateUnavailable={isDateUnavailable}
701701
value={value}
702702
onChange={setValue}
703-
validationState={isInvalid ? 'invalid' : null} />
703+
isInvalid={isInvalid} />
704704
);
705705
}
706706
```

packages/@react-aria/datepicker/docs/useTimeField.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export function TimeField(props) {
111111
{state.segments.map((segment, i) =>
112112
<DateSegment key={i} segment={segment} state={state} />
113113
)}
114-
{state.validationState === 'invalid' &&
114+
{state.isInvalid &&
115115
<span aria-hidden="true">🚫</span>
116116
}
117117
</div>

0 commit comments

Comments
 (0)