-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Try custom dialog for wide legacy widgets #33236
Conversation
Size Change: +1.3 kB (0%) Total Size: 1.08 MB
ℹ️ View Unchanged
|
* | ||
* @return {Object} A ref and resize observer element. | ||
*/ | ||
export function useBudgeTopBy( objective, { isEnabled } ) { |
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.
It's a minor thing, but I feel like the naming could be iterated on. If this is just for use on the widget form it could take naming from that. useWideWidgetPopoverPositioning
or if this could become something more generic useVerticalPopoverPositioning
.
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 tried another name intended to describe the action useAlignTopWithinViewport
but I'd be fine with changing to something like your first suggestion as this isn't intended to for other applications. I do like the idea that this hook could be removed at some point in favor of something more generic.
Popping this out of the Widgets project board since that board is primarily focused on 5.8. |
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.
Realise I've jumped the gun and reviewed a draft again. Hopefully it's helpful.
const subjectRef = useRef(); | ||
const objectiveRef = useRef(); |
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.
Another naming thing, I'm finding these aren't clear enough. I would regularly confuse the subject and the objective.
I think like other popover positioning utilities, it'd be good to stick with the term anchor
for the element that the popover 'achors' to.
target
is a term I find used more than objective, but could also call it popoverRef
to use simpler language.
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've renamed subjectRef
to ref
(it's the one returned by the hook for attachment on the element to be positioned) and objectiveRef
is now anchorRef
.
if ( ! boundsUpdaterRef.current ) { | ||
boundsUpdaterRef.current = () => { | ||
const { defaultView } = subjectRef.current.ownerDocument; | ||
setBounds( { start: 0, end: defaultView.innerHeight } ); | ||
}; | ||
} | ||
|
||
// Sets the bounds height and handles window resizes to update it | ||
useLayoutEffect( () => { | ||
if ( ! hasSubject || ! hasObjective || ! isEnabled ) { | ||
return; | ||
} | ||
boundsUpdaterRef.current(); | ||
const { defaultView } = objective.ownerDocument; | ||
const updateBounds = boundsUpdaterRef.current; | ||
defaultView.addEventListener( 'resize', updateBounds ); | ||
return () => defaultView.removeEventListener( 'resize', updateBounds ); | ||
}, [ hasObjective, hasSubject, isEnabled ] ); |
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.
There's potential to break this down into smaller hooks, e.g. const [ size, [ elementRef ] ] = useViewportSize()
.
Also noticed it subscribes to the objective viewport resize event, but returns the subject size. I think it should always use the objective as that's the element that needs to remain in bounds.
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 had a look a breaking into smaller hooks but wasn't convinced it was helpful for now (adds more lines). Though, there are around, I think, nine instance elsewhere in the repo a useViewportSize
hook could be utilized so maybe it's a hook we should have.
I did as suggested for the listener.
The review is much appreciated @talldan. I'd considered it ready enough, it is drafted because it has an alternative and I thought it might be better broken into smaller PRs. The feedback makes sense and I'll get around to addressing it soon. Thanks! |
c3e54b2
to
8236655
Compare
Exploratory alternative to #33230, following up on #31736 and would close #32210 by obviating the need for it.
This is here for demonstration and if some of the changes here are desired would likely be better to break them off as their own PRs. The high-level changes with some reasoning:
Popover
to display wide widgets with a dialog (withuseDialog
and a custom hook for positioning). Nice in that it requires no modifications to thePopover
component.How has this been tested?
Manually
Screenshots
customizer-widgets-wide-dialog.mp4
Types of changes
Enhancements
Checklist:
*.native.js
files for terms that need renaming or removal).