Adds a handy $parent magic property to your Alpine components.

Overview

Help support the maintenance of this package by sponsoring me.

Alpine $parent

Access parent components using a handy $parent magic variable.

GitHub tag (latest by date) Build size Brotli Monthly downloads via CDN

This package only supports Alpine v3.x.

About

This plugin provides a new $parent magic property that allows you to interact with a parent component's data object directly. This is useful when you have nested components and conflicting property names but would still like to access the parent properties / methods directly.

Installation

CDN

Include the following <script> tag in the <head> of your document, just before Alpine.

<script
    src="https://cdn.jsdelivr.net/npm/@ryangjchandler/[email protected]/dist/cdn.min.js"
    defer
></script>

NPM

npm install @ryangjchandler/alpine-parent

Add the $parent directive to your project by registering the plugin with Alpine.

import Alpine from "alpinejs";
import Parent from "@ryangjchandler/alpine-parent";

Alpine.plugin(Parent);

window.Alpine = Alpine;
window.Alpine.start();

Usage

Access the $parent property in your component:

<div x-data="{ value: 'foo }">
    <div x-data="{ value: 'bar' }">
        My value is <span x-text="value"></span> and my parent's value is <span x-text="$parent.value"></span>
    </div>
</div>

The $parent property returns a Proxy, so any updates to the properties should be reactive. This means you'll be able to use it inside of x-model, etc.

Versioning

This projects follow the Semantic Versioning guidelines.

License

Copyright (c) 2021 Ryan Chandler and contributors

Licensed under the MIT license, see LICENSE.md for details.

You might also like...

Straightforward interactive HTTP requests from within your Alpine.JS markup

Alpine Fetch Straightforward interactive HTTP requests from within your Alpine.JS markup. View the live demo here What does this do? Alpine.JS is a ru

Dec 21, 2022

Calculate the price range for property advertised on Domain and Real Estate.

Calculate the price range for property advertised on Domain and Real Estate.

Property Seeker Calculate the price range for property advertised on Domain and Real Estate. Install Chrome Firefox Edge Privacy All searches are perf

Dec 27, 2022

A plugin that provides utilities for animation property.

tailwindcss-animation-property A plugin that provides utilities for animation property. Not only does the plugin provide the usual animation propertie

Sep 23, 2022

Generate fluid, custom property based design systems on the fly — entirely based on Utopia

Fluid Design Systems With Netlify On-demand Builders A proof of concept demonstrating how Netlify on-demand builders can help generate fluid, custom p

Jan 5, 2023

🤠 Functional utilities using object property paths with wildcards and regexps 🌵

🤠 Functional utilities using object property paths with wildcards and regexps. 🌵 Available functional methods include: 🗺️ Mapping: map() 🚂 Merging

Dec 15, 2022

🤠 Object property paths with wildcards and regexps 🌵

🤠 Object property paths with wildcards and regexps. 🌵 Get/set object properties using: ⛏️ Dot-delimited paths: foo.bar.0.baz ⭐ Wildcards: foo.*, **.

Jan 3, 2023

Explore Alveus Sanctuary with an interactive map and find out more about the different buildings on the property.

Alveus Sanctuary Interactive Map Explore Alveus Sanctuary with an interactive map and find out more about the different buildings on the property. htt

Aug 16, 2022

A jQuery plug-in to notify you of CSS, Attribute or Property changes in an element

selectWatch.js jQuery plug-in gives an opportunity to monitor changes of DOM element's CSS styles, attributes, properties, input element or select ele

Oct 28, 2022

Weather-magic - Working with APIs to create a weather dashboard

Weather-magic - Working with APIs to create a weather dashboard

Weather Magic link to website Following the link above will bring you to the Wea

Feb 3, 2022