Skip to content

Commit 10d3395

Browse files
ryo-manbasnowystingerreidbarber
authored
[RAC] fix: Propagate isDisabled prop from DatePicker to popover Button (#5411)
* fix: Propagate isDisabled prop from DatePicker to popover Button * Update packages/@react-aria/datepicker/src/useDatePicker.ts Co-authored-by: Robert Snow <snowystinger@gmail.com> * remove: unnecessary props * fix: lint --------- Co-authored-by: Robert Snow <snowystinger@gmail.com> Co-authored-by: Reid Barber <reid@reidbarber.com>
1 parent 0da1486 commit 10d3395

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

packages/@react-aria/datepicker/src/useDatePicker.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ export function useDatePicker<T extends DateValue>(props: AriaDatePickerProps<T>
147147
'aria-labelledby': `${buttonId} ${labelledBy}`,
148148
'aria-describedby': ariaDescribedBy,
149149
'aria-expanded': state.isOpen,
150+
isDisabled: props.isDisabled || props.isReadOnly,
150151
onPress: () => state.setOpen(true)
151152
},
152153
dialogProps: {

packages/@react-spectrum/datepicker/src/DatePicker.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ function DatePicker<T extends DateValue>(props: SpectrumDatePickerProps<T>, ref:
4545
autoFocus,
4646
isQuiet,
4747
isDisabled,
48-
isReadOnly,
4948
placeholderValue,
5049
maxVisibleMonths = 1,
5150
pageBehavior
@@ -156,8 +155,7 @@ function DatePicker<T extends DateValue>(props: SpectrumDatePickerProps<T>, ref:
156155
{...mergeProps(buttonProps, focusPropsButton)}
157156
UNSAFE_className={classNames(styles, 'spectrum-FieldButton')}
158157
isQuiet={isQuiet}
159-
validationState={validationState}
160-
isDisabled={isDisabled || isReadOnly}>
158+
validationState={validationState}>
161159
<CalendarIcon />
162160
</FieldButton>
163161
<Dialog UNSAFE_className={classNames(datepickerStyles, 'react-spectrum-Datepicker-dialog')} {...dialogProps}>

packages/react-aria-components/test/DatePicker.test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,4 +255,19 @@ describe('DatePicker', () => {
255255
await user.click(selected.nextSibling.children[0]);
256256
expect(dialog).toBeInTheDocument();
257257
});
258+
259+
it('should disable button and date input when DatePicker is disabled', () => {
260+
let {getByRole} = render(<TestDatePicker isDisabled />);
261+
262+
let button = getByRole('button');
263+
expect(button).toBeDisabled();
264+
265+
let group = getByRole('group');
266+
expect(group).toHaveAttribute('aria-disabled', 'true');
267+
268+
let spinbuttons = within(group).getAllByRole('spinbutton');
269+
for (let spinbutton of spinbuttons) {
270+
expect(spinbutton).toHaveAttribute('aria-disabled', 'true');
271+
}
272+
});
258273
});

0 commit comments

Comments
 (0)