diff --git a/packages/@react-aria/interactions/src/Pressable.tsx b/packages/@react-aria/interactions/src/Pressable.tsx index 75ab45861d3..8c3f88d2899 100644 --- a/packages/@react-aria/interactions/src/Pressable.tsx +++ b/packages/@react-aria/interactions/src/Pressable.tsx @@ -30,14 +30,14 @@ export const Pressable = React.forwardRef(({children, ...props}: PressableProps, if (process.env.NODE_ENV === 'production') { return; } - + let el = ref.current; if (!el || !(el instanceof getOwnerWindow(el).Element)) { console.error(' child must forward its ref to a DOM element.'); return; } - if (!isFocusable(el)) { + if (!props.isDisabled && !isFocusable(el)) { console.warn(' child must be focusable. Please ensure the tabIndex prop is passed through.'); return; } @@ -79,7 +79,7 @@ export const Pressable = React.forwardRef(({children, ...props}: PressableProps, console.warn(` child must have an interactive ARIA role. Got "${role}".`); } } - }, [ref]); + }, [ref, props.isDisabled]); // @ts-ignore let childRef = parseInt(React.version, 10) < 19 ? child.ref : child.props.ref; diff --git a/packages/@react-aria/interactions/test/Pressable.test.js b/packages/@react-aria/interactions/test/Pressable.test.js index 5c16d4064b6..a60548fa7b8 100644 --- a/packages/@react-aria/interactions/test/Pressable.test.js +++ b/packages/@react-aria/interactions/test/Pressable.test.js @@ -117,6 +117,19 @@ describe('Pressable', function () { expect(spy).toHaveBeenCalledWith(' child must be focusable. Please ensure the tabIndex prop is passed through.'); }); + it('supports isDisabled', async function () { + let spy = jest.spyOn(console, 'warn').mockImplementation(() => {}); + let {getByRole} = render( + + Button + + ); + + let button = getByRole('button'); + expect(button).not.toHaveAttribute('tabindex'); + expect(spy).not.toHaveBeenCalled(); + }); + it('should warn if child does not have a role', async function () { let spy = jest.spyOn(console, 'warn').mockImplementation(() => {}); render(