Skip to content

[Backdrop] Call onClick regardless of setClosing prop presence #8237

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 2, 2023

Conversation

loic-d
Copy link
Contributor

@loic-d loic-d commented Feb 1, 2023

WHY are these changes introduced?

I believe #8090 introduced a regression where the onClick prop of the Backdrop component is not called when the consumer of the component also doesn't provide setClosing as a prop (released in Polaris 10.23.0). There are various occurrences of Web Admin using Backdrop without providing setClosing as a prop, so some sheets are not properly closing when clicking outside. For example in Customer Segmentation:

Screenshot 2023-02-01 at 1 40 45 PM

You can reproduce the issue in this CodeSandbox. Switching to a version of Polaris < 10.23.0 fixes the issue.

WHAT is this pull request doing?

This PR ensures onClick is always called, regardless of setClosing being provided.

How to 🎩

🖥 Local development instructions
🗒 General tophatting guidelines
📄 Changelog guidelines

See Playground code. After opening the backdrop, clicking on it again should properly close it.

Copy-paste this code in playground/Playground.tsx:
import React, {useState} from 'react';

import {Backdrop, Button, Page} from '../src';

export function Playground() {
  const [open, setOpen] = useState(false);

  return (
    <Page title="Playground">
      <div style={{ position: "absolute", zIndex: 999999 }}>
        <Button onClick={() => setOpen(!open)}>Toggle backdrop</Button>
      </div>
      {open && (
        <Backdrop
          setClosing={() => {}}
          onClick={() => {
            console.log("onClick from Backdrop");
            setOpen(false);
          }}
        />
      )}
    </Page>
  );
}

You can also 🎩 directly in Admin using this Spin instance:

  • Go to the Customers section
  • Open Segmentation templates

Screenshot 2023-02-01 at 2 18 18 PM

  • Click outside of the sheet. The sheet should properly close.

🎩 checklist

@loic-d
Copy link
Contributor Author

loic-d commented Feb 1, 2023

/snapit

@github-actions
Copy link
Contributor

github-actions bot commented Feb 1, 2023

🫰✨ Thanks @loic-d! Your snapshots have been published to npm.

Test the snapshots by updating your package.json with the newly published versions:

yarn add @shopify/polaris-cli@0.0.0-snapshot-release-20230201184728
yarn add @shopify/polaris@0.0.0-snapshot-release-20230201184728

@github-actions
Copy link
Contributor

github-actions bot commented Feb 1, 2023

size-limit report 📦

Path Size
polaris-react-cjs 215.95 KB (-0.01% 🔽)
polaris-react-esm 137.27 KB (-0.01% 🔽)
polaris-react-esnext 191.59 KB (-0.01% 🔽)
polaris-react-css 41.03 KB (0%)

Copy link
Contributor

@JaKXz JaKXz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @loic-d

Copy link
Contributor

@emmanueletti emmanueletti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the catch and fix!

@loic-d loic-d force-pushed the ld/backdrop-patch branch from 7cfbfdb to 4d84b1b Compare February 2, 2023 14:18
@loic-d loic-d merged commit 17fa970 into main Feb 2, 2023
@loic-d loic-d deleted the ld/backdrop-patch branch February 2, 2023 14:55
laurkim pushed a commit that referenced this pull request Feb 2, 2023
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## @shopify/polaris@10.25.0

### Minor Changes

- [#7950](#7950)
[`286c63a84`](286c63a)
Thanks [@laurkim](https://github.com/laurkim)! - Updated `Tabs`
component to use layout primitives


- [#7950](#7950)
[`286c63a84`](286c63a)
Thanks [@laurkim](https://github.com/laurkim)! - Updated `OptionList` to
use new layout primitives


- [#7950](#7950)
[`286c63a84`](286c63a)
Thanks [@laurkim](https://github.com/laurkim)! - Updated `Popover` to
use new layout primitives

### Patch Changes

- [#7950](#7950)
[`286c63a84`](286c63a)
Thanks [@laurkim](https://github.com/laurkim)! - Remove unused class in
Page Header


- [#7950](#7950)
[`286c63a84`](286c63a)
Thanks [@laurkim](https://github.com/laurkim)! - Rebuilt Page Header
with layout components


- [#8237](#8237)
[`17fa970db`](17fa970)
Thanks [@loic-d](https://github.com/loic-d)! - Fixed Backdrop onClick
callback when setClosing is missing

## @shopify/polaris-cli@0.1.1



## polaris.shopify.com@0.31.1

### Patch Changes

- [#8235](#8235)
[`5fbe75461`](5fbe754)
Thanks [@laurkim](https://github.com/laurkim)! - Updated
Patterns/Typography copy to include suggestions for uppercase typography
styles

- Updated dependencies
\[[`286c63a84`](286c63a),
[`286c63a84`](286c63a),
[`286c63a84`](286c63a),
[`286c63a84`](286c63a),
[`286c63a84`](286c63a),
[`17fa970db`](17fa970)]:
    -   @shopify/polaris@10.25.0

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
sam-b-rose added a commit that referenced this pull request Feb 2, 2023
* main:
  Disallow text transform in stylelint-polaris coverage rules (#8244)
  Add new z-index token names (#8245)
  Version Packages (#8236)
  [Layout foundations][Batch 3] Rebuild components with layout primitives (#7950)
  [Backdrop] Call `onClick` regardless of `setClosing` prop presence (#8237)
@gwyneplaine gwyneplaine mentioned this pull request Feb 14, 2023
juzser pushed a commit to juzser/polaris that referenced this pull request Jul 27, 2023
…hopify#8237)

<!--
  ☝️How to write a good PR title:
- Prefix it with [ComponentName] (if applicable), for example: [Button]
  - Start with a verb, for example: Add, Delete, Improve, Fix…
  - Give as much context as necessary and as little as possible
  - Prefix it with [WIP] while it’s a work in progress
-->

### WHY are these changes introduced?

I believe Shopify#8090 introduced a
regression where the `onClick` prop of the `Backdrop` component is not
called when the consumer of the component also doesn't provide
`setClosing` as a prop (released in Polaris `10.23.0`). There are
various occurrences of Web Admin using `Backdrop` without providing
`setClosing` as a prop, so some sheets are not properly closing when
clicking outside. For example in Customer Segmentation:

<img width="1428" alt="Screenshot 2023-02-01 at 1 40 45 PM"
src="https://user-images.githubusercontent.com/3925905/216133586-92b760bf-57c2-4bfd-9f46-3382d8f935c2.png">

You can reproduce the issue in this
[CodeSandbox](https://codesandbox.io/s/condescending-cannon-7om9z7?file=/App.js:115-155).
Switching to a version of Polaris < `10.23.0` fixes the issue.

### WHAT is this pull request doing?

This PR ensures `onClick` is always called, regardless of `setClosing`
being provided.

### How to 🎩

🖥 [Local development
instructions](https://github.com/Shopify/polaris/blob/main/README.md#local-development)
🗒 [General tophatting
guidelines](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting.md)
📄 [Changelog
guidelines](https://github.com/Shopify/polaris/blob/main/.github/CONTRIBUTING.md#changelog)

<!--
  Give as much information as needed to experiment with the component
  in the playground.
-->

See Playground code. After opening the backdrop, clicking on it again
should properly close it.

<details>
<summary>Copy-paste this code in
<code>playground/Playground.tsx</code>:</summary>

```jsx
import React, {useState} from 'react';

import {Backdrop, Button, Page} from '../src';

export function Playground() {
  const [open, setOpen] = useState(false);

  return (
    <Page title="Playground">
      <div style={{ position: "absolute", zIndex: 999999 }}>
        <Button onClick={() => setOpen(!open)}>Toggle backdrop</Button>
      </div>
      {open && (
        <Backdrop
          setClosing={() => {}}
          onClick={() => {
            console.log("onClick from Backdrop");
            setOpen(false);
          }}
        />
      )}
    </Page>
  );
}

```

</details>

You can also 🎩 directly in Admin using this [Spin
instance](https://admin.web.customer-data-platform-ujet.loic-delaubier.us.spin.dev/store/shop1/customers):

- Go to the Customers section
- Open Segmentation templates
<img width="1189" alt="Screenshot 2023-02-01 at 2 18 18 PM"
src="https://user-images.githubusercontent.com/3925905/216141402-c395b9df-8990-4315-84ca-c88607b759fd.png">

- Click outside of the sheet. The sheet should properly close.

### 🎩 checklist

- [x] 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)
- [ ] Tested for
[accessibility](https://github.com/Shopify/polaris/blob/main/documentation/Accessibility%20testing.md)
- [ ] Updated the component's `README.md` with documentation changes
- [ ] [Tophatted
documentation](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting%20documentation.md)
changes in the style guide
juzser pushed a commit to juzser/polaris that referenced this pull request Jul 27, 2023
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## @shopify/polaris@10.25.0

### Minor Changes

- [Shopify#7950](Shopify#7950)
[`286c63a84`](Shopify@286c63a)
Thanks [@laurkim](https://github.com/laurkim)! - Updated `Tabs`
component to use layout primitives


- [Shopify#7950](Shopify#7950)
[`286c63a84`](Shopify@286c63a)
Thanks [@laurkim](https://github.com/laurkim)! - Updated `OptionList` to
use new layout primitives


- [Shopify#7950](Shopify#7950)
[`286c63a84`](Shopify@286c63a)
Thanks [@laurkim](https://github.com/laurkim)! - Updated `Popover` to
use new layout primitives

### Patch Changes

- [Shopify#7950](Shopify#7950)
[`286c63a84`](Shopify@286c63a)
Thanks [@laurkim](https://github.com/laurkim)! - Remove unused class in
Page Header


- [Shopify#7950](Shopify#7950)
[`286c63a84`](Shopify@286c63a)
Thanks [@laurkim](https://github.com/laurkim)! - Rebuilt Page Header
with layout components


- [Shopify#8237](Shopify#8237)
[`17fa970db`](Shopify@17fa970)
Thanks [@loic-d](https://github.com/loic-d)! - Fixed Backdrop onClick
callback when setClosing is missing

## @shopify/polaris-cli@0.1.1



## polaris.shopify.com@0.31.1

### Patch Changes

- [Shopify#8235](Shopify#8235)
[`5fbe75461`](Shopify@5fbe754)
Thanks [@laurkim](https://github.com/laurkim)! - Updated
Patterns/Typography copy to include suggestions for uppercase typography
styles

- Updated dependencies
\[[`286c63a84`](Shopify@286c63a),
[`286c63a84`](Shopify@286c63a),
[`286c63a84`](Shopify@286c63a),
[`286c63a84`](Shopify@286c63a),
[`286c63a84`](Shopify@286c63a),
[`17fa970db`](Shopify@17fa970)]:
    -   @shopify/polaris@10.25.0

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants