-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[Focus] and [Filters] Fixing initial reference focusing #2871
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
Conversation
0de3b51 to
b86245d
Compare
97fae92 to
0280523
Compare
| children?: React.ReactNode; | ||
| disabled?: boolean; | ||
| root: HTMLElement | null; | ||
| root: React.RefObject<HTMLElement> | HTMLElement | null; |
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 feel like passing the entire ref is safer, but this would break the API of this component - would it make sense to go towards passing the entire ref and add a warning of deprecation for passing only a current element?
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'm a fan of this and would prefer to remove HTMLElement altogether but that can be done in another PR since it would be a breaking change.
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.
Because it's a breaking change, is there a way in Polaris to have a warning for future deprecations?
acd2202 to
a9f551a
Compare
loic-d
left a comment
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.
🎩 looks great. Would be great to get a second 👀 from a Polaris expert cc/ @chloerice 🙌
279a875 to
596bc65
Compare
596bc65 to
22c497b
Compare
kyledurand
left a comment
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.
Looks good I'd just prefer type guarding vs if statement with casting
| children?: React.ReactNode; | ||
| disabled?: boolean; | ||
| root: HTMLElement | null; | ||
| root: React.RefObject<HTMLElement> | HTMLElement | null; |
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'm a fan of this and would prefer to remove HTMLElement altogether but that can be done in another PR since it would be a breaking change.
3f5aaaa to
c7df53c
Compare
c7df53c to
22c0331
Compare
kyledurand
left a comment
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.
Nice 👍
| function isRef( | ||
| ref: React.RefObject<HTMLElement> | HTMLElement, | ||
| ): ref is React.RefObject<HTMLElement> { | ||
| return (ref as React.RefObject<HTMLElement>).current !== undefined; | ||
| } |
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.
👏
WHY are these changes introduced?
Fixes #2741
There are two issues with the current behavior:
WHAT is this pull request doing?
The reference being passed to the
<Focus />component from<Filters />was the direct reference to it'scurrentvalue, which would be a stale reference by the time the component is mounted and rendered, forcing that focused element to be "one step behind."This PR adds an union type to be passed to the
rootof<Focus />, which is the entireReact.RefObject, and lets theFocuscomponent grab it'scurrentnode instead, so that we are sure that thecurrentnode we want to focus on is the node value of the current reference we passed.Choosing to union the type onto the prop for backwards compatibility and not break current consumers.
How to 🎩
To 🎩
yarn devFilterscomponent and thenFilter with resource listMore filtersAccount status🖥 Local development instructions
🗒 General tophatting guidelines
📄 Changelog guidelines
🎩 checklist
README.mdwith documentation changes