-
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
Add controlled prop to open the Tooltip #11714
Conversation
/** Toggle whether the tooltip is visible */ | ||
/** Toggle whether the tooltip is visible. Takes precedence over `active` */ | ||
open?: boolean; | ||
/** Toggle whether the tooltip is visible initially */ | ||
active?: boolean; |
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.
Should we deprecate active
and add the defaultOpen
prop now in anticipation of v13?
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.
Good idea 👍 I'll push up a commit shortly.
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.
Actually, I tentatively think we should handle this in a follow up. I attempted the rename here. However, the active
props seems to have one controlled prop-like behavior in that active={false}
does force the closed state... We can special case the existing active
behavior with conditionals for backward compatibility or just wait till Polaris v13. Thoughts?
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.
Even though defaultOpen
doesn't behave exactly like active
, I think it is worth deprecating active
here and adding defaultOpen
. I think active
is currently an odd prop mix of part-controlled uncontrolled.
I think it would be better to leave the active
behavior as-is until and remove it on the next major.
Alternatively, we introduce a defaultActive
prop and "fix" active to behave like a fully controlled prop (state is external). Though, this strategy would also be a breaking change which would delay Common Action progress
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 it would be better to leave the
active
behavior as-is until and remove it on the next major.
Agreed 👍
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.
Update:
- Added a new
defaultOpen
prop - Deprecated the
active
prop - Special cased the existing
active
prop behavior - Added new test cases for
defaultOpen
- Updated existing test cases to use
defaultOpen
- Added uncontrolled Tooltip examples to Storybook
- Updated existing Storybook entries to use
defaultOpen
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.
Without adding onEnter/onLeave handlers for consumers to control active state within Tooltip itself, how does open
get controlled? I see that it's controlled externally by some other interactive activator element in the story, but the tooltip's presence being controlled by another element doesn't make sense 🤔
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.
That's actually my current use case in the Copy to Clipboard recipe (e.g. the copy button triggers a timeout which sets open={true}
only). However, I agree with the sentiment it is more conventional to show controlled component examples with the state and handlers 👍 Updated! 7619a24
Co-authored-by: Chloe Rice <[email protected]>
/** Toggle whether the tooltip is visible */ | ||
/** Toggle whether the tooltip is visible. Takes precedence over `active` */ | ||
open?: boolean; | ||
/** Toggle whether the tooltip is visible initially */ | ||
active?: boolean; |
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.
Even though defaultOpen
doesn't behave exactly like active
, I think it is worth deprecating active
here and adding defaultOpen
. I think active
is currently an odd prop mix of part-controlled uncontrolled.
I think it would be better to leave the active
behavior as-is until and remove it on the next major.
Alternatively, we introduce a defaultActive
prop and "fix" active to behave like a fully controlled prop (state is external). Though, this strategy would also be a breaking change which would delay Common Action progress
cc @chloerice @laurkim @sam-b-rose requested new reviews as a LOT has changed per the discussion here |
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.
Works great @aaronccasanova, can't wait to be rid of that active
prop 🙌🏽 🚀
/snapit |
🫰✨ Thanks @aaronccasanova! Your snapshots have been published to npm. Test the snapshots by updating your yarn add @shopify/[email protected] yarn add @shopify/[email protected] |
This reverts commit 2f0cbca.
Reverts #11714 @chloerice and I are exploring an alternative pattern for hybrid controlled/uncontrolled component state management.
WHAT is this pull request doing?
This PR introduces a controlled component prop named
open
to theTooltip
. This feature is being added to support upcoming Common Actions guidance for Copy to Clipboard buttons.Currently, the Tooltip provides an
active
prop which only sets the initial open state. Note: The newopen
prop takes precedence overactive
. I suggest we renameactive
todefaultOpen
in a future major release for consistency with other (un)controlled component patterns (e.g.<input />
,value
, anddefaultValue
) and help disambiguate the props.UPDATE: Per the discussion here, we have opt'd to include the proposed
defaultProp
and deprecate theactive
prop as part of this PR e.g.defaultOpen
propactive
propactive
prop behaviordefaultOpen
defaultOpen
Tooltip
examples to StorybookdefaultOpen
Example setting
open={true}
for the duration of thecopied
status timeout:Screen.Recording.2024-03-01.at.3.11.05.PM.mov
How to 🎩
🖥 Local development instructions
🗒 General tophatting guidelines
📄 Changelog guidelines
🎩 checklist
README.md
with documentation changes