Skip to content

Commit

Permalink
fix some teleportal typos in comments, tests and documentation. (alpi…
Browse files Browse the repository at this point in the history
  • Loading branch information
lupinitylabs authored Dec 1, 2021
1 parent cba98a6 commit 76f0b73
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
6 changes: 3 additions & 3 deletions packages/alpinejs/src/directives/x-teleport.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { addScopeToNode } from "../scope"
directive('teleport', (el, { expression }, { cleanup }) => {
let target = document.querySelector(expression)
let clone = el.content.cloneNode(true).firstElementChild
// Add reference to element on <template x-portal, and visa versa.

// Add reference to element on <template x-teleport, and visa versa.
el._x_teleport = clone
clone._x_teleportBack = el

Expand All @@ -16,7 +16,7 @@ directive('teleport', (el, { expression }, { cleanup }) => {
el._x_forwardEvents.forEach(eventName => {
clone.addEventListener(eventName, e => {
e.stopPropagation()

el.dispatchEvent(new e.constructor(e.type, e))
})
})
Expand Down
6 changes: 3 additions & 3 deletions packages/alpinejs/src/lifecycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,17 @@ export function closestRoot(el, includeInitSelectors = false) {
const selectors = includeInitSelectors ? allSelectors() : rootSelectors()

if (selectors.some(selector => element.matches(selector))) return true
})
})
}

export function findClosest(el, callback) {
if (! el) return

if (callback(el)) return el

// Support crawling up portals.
// Support crawling up teleports.
if (el._x_teleportBack) el = el._x_teleportBack

if (! el.parentElement) return

return findClosest(el.parentElement, callback)
Expand Down
4 changes: 2 additions & 2 deletions packages/docs/src/en/directives/teleport.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ Notice how when toggling the modal, the actual modal contents show up AFTER the
<a name="forwarding-events"></a>
## Forwarding events

Alpine tries it's best to make the experience of telporting seemless. Anything you would normally do in a template, you should be able to do inside an `x-teleport` template. Teleported content can access the normal Alpine scope of the component as well as other features like `$refs`, `$root`, etc...
Alpine tries it's best to make the experience of teleporting seamless. Anything you would normally do in a template, you should be able to do inside an `x-teleport` template. Teleported content can access the normal Alpine scope of the component as well as other features like `$refs`, `$root`, etc...

However, native DOM events have no concept of teleportation, so if, for example, you trigger a "click" event from inside a teleported element, that event will bubble up the DOM tree as it normally would.

To make this experience more seemless, you can "forward" events by simply registering event listeners on the `<template x-teleport...>` element itself like so:
To make this experience more seamless, you can "forward" events by simply registering event listeners on the `<template x-teleport...>` element itself like so:

```alpine
<div x-data="{ open: false }">
Expand Down
4 changes: 2 additions & 2 deletions tests/cypress/integration/directives/x-teleport.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ test('removing teleport source removes teleported target',
},
)

test('$refs inside telport can be accessed outside',
test('$refs inside teleport can be accessed outside',
[html`
<div x-data="{ count: 1 }" id="a">
<button @click="$refs.count.remove()">Remove</button>
Expand Down Expand Up @@ -119,7 +119,7 @@ test('$root is accessed outside teleport',
},
)

test('$id honors x-id outside telport',
test('$id honors x-id outside teleport',
[html`
<div x-data="{ count: 1 }" id="a" x-id="['foo']">
<h1 x-text="$id('foo')"></h1>
Expand Down
12 changes: 6 additions & 6 deletions tests/cypress/integration/plugins/morph.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ test('can morph components and preserve Alpine state',
get('span').should(haveText('bar'))
get('button').click()
get('span').should(haveText('baz'))

get('div').then(([el]) => window.Alpine.morph(el, toHtml))

get('span').should(haveText('baz'))
Expand All @@ -35,7 +35,7 @@ test('morphing target uses outer Alpine scope',
get('span').should(haveText('bar'))
get('button').click()
get('span').should(haveText('baz'))

get('div').then(([el]) => window.Alpine.morph(el, toHtml))

get('span').should(haveText('baz'))
Expand All @@ -58,7 +58,7 @@ test('can morph with HTML change and preserve Alpine state',
get('button').should(haveText('Change Foo'))

get('div').then(([el]) => window.Alpine.morph(el, toHtml))

get('span').should(haveText('baz'))
get('button').should(haveText('Changed Foo'))
},
Expand Down Expand Up @@ -87,13 +87,13 @@ test('morphing an element with multiple nested Alpine components preserves scope
get('h1').should(haveText('law'))

get('div').then(([el]) => window.Alpine.morph(el, toHtml))

get('span').should(haveText('baz'))
get('h1').should(haveText('law'))
},
)

test('can morph portals',
test('can morph teleports',
[html`
<div x-data="{ count: 1 }" id="a">
<button @click="count++">Inc</button>
Expand Down Expand Up @@ -126,7 +126,7 @@ test('can morph portals',
get('button').click()
get('h1').should(haveText('2'))
get('h2').should(haveText('hey'))

get('div#a').then(([el]) => window.Alpine.morph(el, toHtml))

get('h1').should(haveText('2'))
Expand Down

0 comments on commit 76f0b73

Please sign in to comment.