Skip to content

Commit 4ffc040

Browse files
authored
Provider shouldn't disable buttons inside dialogs (#3587)
ContextualHelp dialog button should not be disabled by outer provider, such as Form
1 parent 5c9db40 commit 4ffc040

File tree

2 files changed

+56
-2
lines changed

2 files changed

+56
-2
lines changed

packages/@react-spectrum/form/test/Form.test.js

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,31 @@
1010
* governing permissions and limitations under the License.
1111
*/
1212

13+
import {act} from 'react-dom/test-utils';
1314
import {Button} from '@react-spectrum/button';
15+
import {Content, Header} from '@react-spectrum/view';
16+
import {ContextualHelp} from '@react-spectrum/contextualhelp';
1417
import {Form} from '../';
1518
import {Item, Picker} from '@react-spectrum/picker';
19+
import MatchMediaMock from 'jest-matchmedia-mock';
1620
import {Provider} from '@react-spectrum/provider';
1721
import React from 'react';
18-
import {render} from '@react-spectrum/test-utils';
22+
import {render, triggerPress} from '@react-spectrum/test-utils';
1923
import {TextField} from '@react-spectrum/textfield';
2024
import {theme} from '@react-spectrum/theme-default';
2125
import userEvent from '@testing-library/user-event';
26+
import {within} from '@testing-library/dom';
2227

2328
describe('Form', function () {
29+
let matchMedia;
30+
beforeAll(() => {
31+
jest.useFakeTimers();
32+
});
33+
34+
beforeEach(() => {
35+
matchMedia = new MatchMediaMock();
36+
});
37+
2438
it('should render a form', () => {
2539
let {getByRole} = render(
2640
<Provider theme={theme}>
@@ -183,5 +197,45 @@ describe('Form', function () {
183197
let form = getByRole('form');
184198
expect(form.elements['picker'].value).toEqual('one');
185199
});
200+
201+
it('contextual help should not be disabled nor should its dismiss button be disabled', () => {
202+
matchMedia.useMediaQuery('(max-width: 700px)');
203+
204+
let {getByRole, getByLabelText} = render(
205+
<Provider theme={theme}>
206+
<Form aria-label="Test" isDisabled>
207+
<Picker
208+
name="picker"
209+
defaultSelectedKey="one"
210+
label="Test Picker"
211+
contextualHelp={(
212+
<ContextualHelp>
213+
<Header>What is it good for?</Header>
214+
<Content>Absolutely nothing.</Content>
215+
</ContextualHelp>
216+
)}>
217+
<Item key="one">One</Item>
218+
<Item key="two">Two</Item>
219+
<Item key="three">Three</Item>
220+
</Picker>
221+
</Form>
222+
</Provider>
223+
);
224+
225+
let button = getByLabelText('Help');
226+
triggerPress(button);
227+
228+
let dialog = getByRole('dialog');
229+
userEvent.tab();
230+
231+
let dismissButton = within(dialog).getByRole('button');
232+
expect(document.activeElement).toBe(dismissButton);
233+
234+
triggerPress(dismissButton);
235+
act(() => {jest.runAllTimers();});
236+
act(() => {jest.runAllTimers();});
237+
238+
expect(document.activeElement).toBe(button);
239+
});
186240
});
187241
});

packages/@react-spectrum/overlays/src/Overlay.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function Overlay(props: OverlayProps, ref: DOMRef<HTMLDivElement>) {
4343
}
4444

4545
let contents = (
46-
<Provider ref={ref} UNSAFE_style={{background: 'transparent', isolation: 'isolate'}}>
46+
<Provider ref={ref} UNSAFE_style={{background: 'transparent', isolation: 'isolate'}} isDisabled={false}>
4747
<OpenTransition
4848
in={isOpen}
4949
appear

0 commit comments

Comments
 (0)