Skip to content
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

Fix teleport morphing #3841

Merged
merged 6 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions packages/focus/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,13 @@ export default function (Alpine) {

// Start trapping.
if (value && ! oldValue) {
setTimeout(() => {
if (modifiers.includes('inert')) undoInert = setInert(el)
if (modifiers.includes('noscroll')) undoDisableScrolling = disableScrolling()
if (modifiers.includes('noscroll')) undoDisableScrolling = disableScrolling()
if (modifiers.includes('inert')) undoInert = setInert(el)

// Activate the trap after a generous tick. (Needed to play nice with transitions...)
setTimeout(() => {
trap.activate()
});
}, 15)
}

// Stop trapping.
Expand Down
9 changes: 5 additions & 4 deletions packages/morph/src/morph.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ export function morph(from, toHtml, options) {
}

function patchChildren(from, to) {
// If we hit a <template x-teleport="body">,
// let's use the teleported nodes for this patch...
if (from._x_teleport) from = from._x_teleport
if (to._x_teleport) to = to._x_teleport

let fromKeys = keyToMap(from.children)
let fromKeyHoldovers = {}

Expand Down Expand Up @@ -444,10 +449,6 @@ function getFirstNode(parent) {
}

function getNextSibling(parent, reference) {
if (reference._x_teleport) {
return reference._x_teleport
}

let next

if (parent instanceof Block) {
Expand Down
12 changes: 9 additions & 3 deletions packages/ui/src/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,20 @@ function handleRoot(el, Alpine) {
__itemEls: [],
__activeEl: null,
__isOpen: false,
__open() {
__open(activationStrategy) {

this.__isOpen = true

// Safari needs more of a "tick" for focusing after x-show for some reason.
// Probably because Alpine adds an extra tick when x-showing for @click.outside
let nextTick = callback => requestAnimationFrame(() => requestAnimationFrame(callback))

nextTick(() => this.$refs.__items.focus({ preventScroll: true }))
nextTick(() => {
this.$refs.__items.focus({ preventScroll: true })

// Activate the first item every time the menu is open...
activationStrategy && activationStrategy(Alpine, this.$refs.__items, el => el.__activate())
})
},
__close(focusAfter = true) {
this.__isOpen = false
Expand Down Expand Up @@ -67,7 +73,7 @@ function handleButton(el, Alpine) {
'x-init'() { if (this.$el.tagName.toLowerCase() === 'button' && ! this.$el.hasAttribute('type')) this.$el.type = 'button' },
'@click'() { this.$data.__open() },
'@keydown.down.stop.prevent'() { this.$data.__open() },
'@keydown.up.stop.prevent'() { this.$data.__open(dom.Alpine, last) },
'@keydown.up.stop.prevent'() { this.$data.__open(dom.last) },
'@keydown.space.stop.prevent'() { this.$data.__open() },
'@keydown.enter.stop.prevent'() { this.$data.__open() },
})
Expand Down