Skip to content

Commit 91781af

Browse files
emmanuelettiJaKXzkyledurand
authored andcommitted
Removing mouse up and mouse down from modal Backdrop component (Shopify#8090)
[Spin instance](https://polaris.polaris-f45t.emmanuel-etti.us.spin.dev/) ### WHY are these changes introduced? - Closes Shopify#8144 - Modal component closes when a user selects within the modal (for example, in an input field while selecting typed input) but overshoots the modal boundaries and releases their mouse outside the modal (in the backdrop). ### WHAT is this pull request doing? - Removes the `onMouseUp` and `onMouseDown` handles from `Backdrop` component. There is a test that covers this case of explicitly clicking the backdrop to close it and we think that is sufficient behaviour. ### Before https://user-images.githubusercontent.com/78582921/213541746-f3304f21-737f-411b-aea1-a8cc35264e57.mov ### After https://user-images.githubusercontent.com/78582921/214117861-d8866a19-b45d-4d08-a94f-cd467199a3b5.mov ### 🎩 checklist - [ ] Tested on [mobile](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting.md#cross-browser-testing) - [x] Tested on [multiple browsers](https://help.shopify.com/en/manual/shopify-admin/supported-browsers) - [x] Tested for [accessibility](https://github.com/Shopify/polaris/blob/main/documentation/Accessibility%20testing.md) Co-authored-by: Jason Kurian <jason.kurian@shopify.com> Co-authored-by: Kyle Durand <kyledurand@users.noreply.github.com>
1 parent 34036d7 commit 91781af

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

.changeset/gentle-chefs-hear.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/polaris': patch
3+
---
4+
5+
Replaced mouse up and down events on Backdrop with onClick to close Modal

polaris-react/src/components/Backdrop/Backdrop.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export function Backdrop(props: BackdropProps) {
2929
}
3030
};
3131

32-
const handleMouseUp = () => {
32+
const handleClick = () => {
3333
if (setClosing && onClick) {
3434
setClosing(false);
3535
onClick();
@@ -41,10 +41,9 @@ export function Backdrop(props: BackdropProps) {
4141
<ScrollLock />
4242
<div
4343
className={className}
44-
onClick={onClick}
44+
onClick={handleClick}
4545
onTouchStart={onTouchStart}
4646
onMouseDown={handleMouseDown}
47-
onMouseUp={handleMouseUp}
4847
/>
4948
</>
5049
);

polaris-react/src/components/Backdrop/tests/Backdrop.test.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ import {mountWithApp} from 'tests/utilities';
44
import {Backdrop} from '..';
55

66
describe('<Backdrop />', () => {
7-
describe('onDismiss()', () => {
7+
describe('onClick()', () => {
88
it('is called when the backdrop is clicked', () => {
99
const spy = jest.fn();
10-
const backdrop = mountWithApp(<Backdrop onClick={spy} />);
11-
backdrop.find('div', {onClick: spy})!.trigger('onClick');
10+
const backdrop = mountWithApp(
11+
<Backdrop onClick={spy} setClosing={() => {}} />,
12+
);
13+
backdrop.find('div')!.trigger('onClick');
1214
expect(spy).toHaveBeenCalled();
1315
});
1416
});

0 commit comments

Comments
 (0)