-
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
[TextField] Allow click event on spinner (stepper in number type) #6719
Conversation
59c1225
to
c6857dd
Compare
c6857dd
to
f894d07
Compare
size-limit report 📦
|
return Boolean(multiline) || multiline > 0 | ||
? {'aria-multiline': true} | ||
: undefined; | ||
function handleKeyPress(event: React.KeyboardEvent) { |
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 just moved these functions to be alphabetical so it's easier to read/find. It shouldn't affect the git blame
if I'm not mistaken? 🤞🏽
/snapit |
🫰✨ Thanks @ginabak! Your snapshots have been published to npm. Test the snapshots by updating your yarn add @shopify/polaris-icons@0.0.0-snapshot-release-20220725143855 yarn add @shopify/polaris@0.0.0-snapshot-release-20220725143855 |
'@shopify/polaris': major | ||
--- | ||
|
||
Allow click events for spinner in [TextField] |
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.
spinner (so confusing, I know), is not the actual "loading" spinner, it's this component that has a confusing name, which is the 🔼 and the 🔽 (the stepper) portion of the TextField.
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.
awesome! Nice to see this one coming together 🙂
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.
🎩 and code looks great!
@@ -629,7 +591,7 @@ export function TextField({ | |||
} | |||
|
|||
function handleClickChild(event: React.MouseEvent) { | |||
if (inputRef.current !== event.target) { | |||
if (!isSpinner(event.target) && !isInput(event.target)) { |
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.
Hey @ginabak 👋🏽 Thanks for raising this! I think you will need to also add isSpinner
to the conditional on line 581 in the handleClick
method to prevent the input focus toggle/flash with each click of the spinner.
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.
Hi hi @chloerice ! GOOD CATCH, OMG! Thank-you! 😄 !
8977c12
to
1ef8903
Compare
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.
🚀
co-author: @weslleyaraujo
WHY are these changes introduced?
Fixes #6725
Part of https://github.com/Shopify/inventory-states-ux/issues/524
Follow up to #6129 https://github.com/Shopify/web/pull/68974
As of Polaris 9.12.0, we no longer bubble up click events emitted on
TextField
and parent elements can no longer depend on interactions. This change was introduced here.Click events do not bubble for the
Spinner
(see here) portion of the Textfield. The spinner is the 🔼 and 🔽 when thetype='number'
. This is problematic for when we need to implement onClick events around the TextField. This current monorail schema measures whether or not a merchant used the stepper / spinner to adjust their inventory quantity. Theevent.stopPropagation()
no longer allows us to capture this data 😢 and will always return false.WHAT is this pull request doing?
This PR will conditionally call stopPropagation when click events are captured by TextField and parent elements.
If it is either the
spinner
or aninput
, it will no longer call thestopPropagation
.BEFORE
stepper.click.not.propagated.mp4
AFTER
propagation.works.mp4
How to 🎩
🖥 Local development instructions
🗒 General tophatting guidelines
📄 Changelog guidelines
Copy-paste this code in
playground/Playground.tsx
:There should be two
TextField
s rendered in your playground and one of them contains aBadge
as itsverticalContent
prop.TextField
TextField
click directly on theBadge
(not the input field)🎩 checklist
README.md
with documentation changes