This repository was archived by the owner on Sep 30, 2024. It is now read-only.
Svelte: allow popovers to have external targets#63141
Merged
Merged
Conversation
camdencheek
commented
Jun 6, 2024
Comment on lines
+18
to
+19
| export let trigger: HTMLElement | null = null | ||
| export let target: HTMLElement | undefined = undefined |
Member
Author
There was a problem hiding this comment.
Primary new change: expose trigger and target so they can be passed in directly rather than only via the registerTrigger/registerTarget actions.
camdencheek
commented
Jun 6, 2024
| Using a link here allows us to benefit from data preloading. | ||
| --> | ||
| <Popover let:registerTrigger placement="right-end" showOnHover> | ||
| <Popover trigger={label} placement="right-start" showOnHover offset={{ mainAxis: 8, crossAxis: -32 }}> |
Member
Author
There was a problem hiding this comment.
This is how the passed-in trigger looks. (the change in placement and offset is not related, but necessary to make this look okay)
fkling
approved these changes
Jun 7, 2024
Comment on lines
+104
to
111
| // Every time trigger changes (either by a props change or a call to registerTrigger) | ||
| // unwatch the old trigger and watch the new trigger. | ||
| let oldTrigger: HTMLElement | null | ||
| $: { | ||
| oldTrigger && unwatchTrigger(oldTrigger) | ||
| trigger && watchTrigger(trigger) | ||
| oldTrigger = trigger | ||
| } |
Contributor
There was a problem hiding this comment.
I hope we can eventually provide a nice API for this use case, which is basically an effect with cleanup logic. Maybe something like
const trackedTrigger = track(trigger => {
if (trigger) {
watchTrigger(trigger)
return () => unwatchTrigger(trigger)
}
})
$: trackedTrigger.set(trigger)
Member
Author
There was a problem hiding this comment.
Agreed! I was honestly kinda surprised that there wasn't something built in to svelte to get the previous value of the variable.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This updates the
Popovercomponent to accept a passed-in target rather than setting the target via an action. This allows us to pass in targets not owned by thePopovercomponent, which is important for things like the file tree where the logical target is a wrapper around what the consumer has access to.Test plan
Manually tested. Video walkthrough.