-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[Collapsible] Add support for disabling the transition, and fix state machine #7364
Conversation
size-limit report 📦
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking good for 0ms | 0s
durations but there's a wee update loop bug when a non-zero duration is passed in.
collapsible.mp4
I can give you a hand tomorrow or Monday if you want it
Once we get rid of the loop we should:
- Make sure this works with nested Collapsible components
- Make sure this covers the needs of the last two contributors
/snapit
and ping folks for 🎩
.changeset/light-houses-repeat.md
Outdated
|
||
Deprecated Collapsible preventMeasuringOnChildrenUpdate. | ||
Fixed bug where Collapsible would get stuck in animating state. | ||
Support for 0ms transition duration in Collapsible. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also fixes #4194 👏
/snapit |
🫰✨ Thanks @aishad! Your snapshots have been published to npm. Test the snapshots by updating your yarn add @shopify/plugin-polaris@0.0.0-snapshot-release-20221006204649 yarn add @shopify/polaris-migrator@0.0.0-snapshot-release-20221006204649 yarn add @shopify/polaris@0.0.0-snapshot-release-20221006204649 |
Thanks for finding this! This was caused by adding a new dependency to the I also found thanks to your comment that I notice in the Storybook for Collapsible that it sets the |
I 🎩 to make sure there was no regression for our use case, and all looks good. |
This blog shows how to get the value from a CSS property: https://www.designcise.com/web/tutorial/how-to-get-the-value-of-a-css-variable-using-javascript In theory in this component we could do the following code: const duration = transition?.duration;
const disableTransition = useMemo(() => {
if(!duration || !collapsibleContainer.current) return false;
if(/^0+(ms|s)$/.test(duration.trim()) return true;
const styles = getComputedStyle(collapsibleContainer.current);
const computedDuration = styles.getPropertyValue(duration);
return /^0+(ms|s)$/.test(computedDuration);
}, [duration]); |
I'd prefer a prop over reading computed styles. I left this thought in slack but I'll leave it here as well for others to chime in but what if we merged the /** Assign transition properties to the collapsible
* @default true
*/
transition?: boolean | Transition; <Collapsible transition="false" />
<Collapsible transition={{duration: 'var(--p-duration-150)', timingFunction: 'var(--p-ease-in-out)'}} /> |
/snapit |
🫰✨ Thanks @kyledurand! Your snapshots have been published to npm. Test the snapshots by updating your yarn add @shopify/plugin-polaris@0.0.0-snapshot-release-20221007160227 yarn add @shopify/polaris-migrator@0.0.0-snapshot-release-20221007160227 yarn add @shopify/polaris@0.0.0-snapshot-release-20221007160227 |
/snapit |
/snapit |
🫰✨ Thanks @Bringer128! Your snapshots have been published to npm. Test the snapshots by updating your yarn add @shopify/plugin-polaris@0.0.0-snapshot-release-20221007203242 yarn add @shopify/polaris-migrator@0.0.0-snapshot-release-20221007203242 yarn add @shopify/polaris@0.0.0-snapshot-release-20221007203242 |
/snapit |
@kyledurand I've updated the PR description based on the solution we chose; and would love your fresh 👀 . I've tested nested Collapsibles and a few browsers and it all seems to work fine. |
🫰✨ Thanks @Bringer128! Your snapshots have been published to npm. Test the snapshots by updating your yarn add @shopify/plugin-polaris@0.0.0-snapshot-release-20221011180026 yarn add @shopify/polaris-migrator@0.0.0-snapshot-release-20221011180026 yarn add @shopify/polaris@0.0.0-snapshot-release-20221011180026 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking really good. My main concern would be disabling transition when 0 values are passed in as duration. Adding that means consumers don't have to use the new false
flag for disabling the transition
transition?: Transition; | ||
/** Prevents component from re-measuring when child is updated **/ | ||
/** Override transition properties. When set to false, disables transition completely. Defaults to true, which uses | ||
* default transition properties. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* default transition properties. | |
* @default transition={{duration: 'var(--p-duration-150)', timingFunction: 'var(--p-ease-in-out)'}} |
@@ -51,11 +53,14 @@ export function Collapsible({ | |||
expandOnPrint && styles.expandOnPrint, | |||
); | |||
|
|||
const transitionDisabled = transition === false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we still care about transition.duration being 0 || 0ms || 0s
here. Can we disable transition on those values as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed in Slack, the CSS spec requires the unit for the transition-duration
field so I'm not addressing the 0
scenario.
polaris-react/src/components/Collapsible/tests/Collapsible.test.tsx
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👏 Fantastic work @Bringer128. Thanks for taking this on 🥇
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-migrator@0.5.0 ### Minor Changes - [#7373](#7373) [`56c82ee8d`](56c82ee) Thanks [@aaronccasanova](https://github.com/aaronccasanova)! - Add `getFunctionArgs` utility ### Patch Changes - Updated dependencies \[[`c3f427c17`](c3f427c)]: - @shopify/polaris-tokens@6.2.1 ## @shopify/polaris@10.8.0 ### Minor Changes - [#7364](#7364) [`e4b2c36d8`](e4b2c36) Thanks [@Bringer128](https://github.com/Bringer128)! - Deprecated Collapsible preventMeasuringOnChildrenUpdate. Fixed bug where Collapsible would get stuck in animating state when duration is 0. Add support for intentionally disabling the transition in Collapsible. ### Patch Changes - [#7363](#7363) [`8a6c323e2`](8a6c323) Thanks [@aveline](https://github.com/aveline)! - Added `id` prop to `Text` and `Box` - [#7348](#7348) [`ea2a45bbb`](ea2a45b) Thanks [@aveline](https://github.com/aveline)! - Added `setMediaWidth` breakpoints test utility - [#7388](#7388) [`5bc885765`](5bc8857) Thanks [@kyledurand](https://github.com/kyledurand)! - Fixed a re-render bug with Page Actions - Updated dependencies \[[`c3f427c17`](c3f427c)]: - @shopify/polaris-tokens@6.2.1 ## @shopify/plugin-polaris@0.0.11 ### Patch Changes - Updated dependencies \[[`56c82ee8d`](56c82ee)]: - @shopify/polaris-migrator@0.5.0 ## @shopify/polaris-tokens@6.2.1 ### Patch Changes - [#7385](#7385) [`c3f427c17`](c3f427c) Thanks [@laurkim](https://github.com/laurkim)! - Refactored exported alias and scale types in `breakpoints`, `depth`, `font`, `motion`, `shape`, `spacing`, and `zIndex`. ## @shopify/stylelint-polaris@4.3.2 ### Patch Changes - Updated dependencies \[[`c3f427c17`](c3f427c)]: - @shopify/polaris-tokens@6.2.1 ## polaris.shopify.com@0.22.0 ### Minor Changes - [#7032](#7032) [`40ee692aa`](40ee692) Thanks [@gwyneplaine](https://github.com/gwyneplaine)! - Added Playroom integration to Polaris docs site. ### Patch Changes - [#7032](#7032) [`40ee692aa`](40ee692) Thanks [@gwyneplaine](https://github.com/gwyneplaine)! - Improved the design of the Sandbox feature. - [#7400](#7400) [`9f9fe1f99`](9f9fe1f) Thanks [@kyledurand](https://github.com/kyledurand)! - Fixed a scaling bug caused by content overflow Fixed a bug where examples that don't have any content wouldn't show up - Updated dependencies \[[`8a6c323e2`](8a6c323), [`e4b2c36d8`](e4b2c36), [`c3f427c17`](c3f427c), [`ea2a45bbb`](ea2a45b), [`5bc885765`](5bc8857)]: - @shopify/polaris@10.8.0 - @shopify/polaris-tokens@6.2.1 ## polaris-for-figma@0.0.24 ### Patch Changes - Updated dependencies \[[`8a6c323e2`](8a6c323), [`e4b2c36d8`](e4b2c36), [`ea2a45bbb`](ea2a45b), [`5bc885765`](5bc8857)]: - @shopify/polaris@10.8.0 Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
WHY are these changes introduced?
Fixes #7318
Today the Collapsible component can get stuck in the "animating" state for 2 reasons, both of which cause the
onTransitionEnd
event not to fire.transition={{ duration: "0ms" }}
is used as Navigation Items does.open=true
(as raised in the linked issue). This causes thediv
to havemax-height
not change, which means the transition does not occur.Fundamentally the issue with this component is that it relies on the
onTransitionEnd
event to move out of theanimating
state. There are 2 ways that this event won't fire, similarly related:0ms
,0s
or-some-var-that-evaluates-to-0
)This PR does not solve the dependency on the
onTransitionEnd
event. Instead it:transition={false}
. This prevents the need to pass0ms
duration. (Note this does not stop the bug occurring)0ms
or0s
to also disable the transition.As such there will still be a bug if the computed height of
children
is set to 0px. However I'm choosing not to address this in this PR as the chances are rare. To trigger this bug you must:open={false}
)0px
high as computed byelement.scrollHeight
WHAT is this pull request doing?
false
to thetransition
prop to disable the transition.Navigation
Secondary
component to usetransition={false}
How to 🎩
🖥 Local development instructions
🗒 General tophatting guidelines
📄 Changelog guidelines
Copy-paste this code in
playground/Playground.tsx
:The code has 6 scenarios:
Collapsible
withul
as its child (this has margin-top and margin-bottom)Collapsible
withdiv
as its child (this has no margins)Collapsible
that has children that is 0px high (not fixed by this PR)🎩 checklist
README.md
with documentation changes