-
Notifications
You must be signed in to change notification settings - Fork 342
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* fix(#3577): introduce useTeleported composable * chore(docs): update modal demo * fix(time-input): open on click * chore(docs): change button in example to primary * fix(dropdown): close on keyboard only focus outside
- Loading branch information
Showing
9 changed files
with
139 additions
and
28 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { useCurrentComponentId } from './useCurrentComponentId' | ||
|
||
export const TELEPORT_FROM_ATTR = 'data-va-teleported-from' | ||
export const TELEPORT_ATTR = 'data-va-teleported' | ||
|
||
export const findTeleportedFrom = (el: HTMLElement | undefined | null): HTMLElement | null => { | ||
if (!el) { return null } | ||
|
||
const teleportId = el.getAttribute(TELEPORT_ATTR) | ||
|
||
if (teleportId === null) { return findTeleportedFrom(el.parentElement) } | ||
|
||
return document.querySelector<HTMLElement>(`[${TELEPORT_FROM_ATTR}="${teleportId}"]`) | ||
} | ||
|
||
/** | ||
* Used in components, which have something to do with Teleport. | ||
* You need to add `teleportFromAttrs` to the root element of the component, | ||
* and `teleportedAttrs` to the element, which is teleported. | ||
* | ||
* This way you can find the original element, which was teleported from. | ||
* | ||
* @notice it is used in `useClickOutside` to track from where teleported originated from. | ||
*/ | ||
export const useTeleported = () => { | ||
const componentId = useCurrentComponentId() | ||
|
||
return { | ||
teleportFromAttrs: { | ||
[TELEPORT_FROM_ATTR]: componentId, | ||
}, | ||
teleportedAttrs: { | ||
[TELEPORT_ATTR]: componentId, | ||
}, | ||
findTeleportedFrom, | ||
} | ||
} |