Comments (6)
Thanks @adrienpoly. Using super
isn't much of a concern, I know that'd work.
What I don't know is how to append items to the static targets
array. It'd be nice not having to redefine that and simply add new targets in. I also wondered if redefining a static variable would throw an error or not.
from tailwindcss-stimulus-components.
Updated the readme with an example of this.
from tailwindcss-stimulus-components.
This is fairly easy to achieve with standard ES6 class inheritance.
I am using this very often and described it in the Flatpickr Stimulus Wrapper I did.
Here is the relevant documentation :
https://github.com/adrienpoly/stimulus-flatpickr#extends-the-controller
For the Modal
controller it would look something like that:
//controllers/modal_controller.js
import { Modal } from "tailwindcss-stimulus-components"
export default class extends Modal {
connect() {
//your custom connect code
super.connect(); // always call super to run parent connect code
};
open(e) {
//your custom open code
super.open(e); // always call super to run parent open code
};
}
from tailwindcss-stimulus-components.
From a quick test, it looks like you can rewrite it as static, but not modify the array. We may be able to just remove the static
from our components to make these extendable.
class SuperDropdown extends Dropdown {
static targets = [ 'menu', 'extra' ]
}
console.log(SuperDropdown.targets)
// ['menu', 'extra']
class SuperDropdown extends Dropdown {
connect() {
this.targets.push('extra')
super.connect()
}
}
console.log(SuperDropdown.targets)
// ['menu']
from tailwindcss-stimulus-components.
Ok I didn't though initially about the targets
that is indeed a good point. From my testing I think this works out of the box.
you can have a look at this example :
https://glitch.com/edit/#!/pepper-dingo?path=src/controllers/super-input_controller.js:10:1
The extended controller
//controllers/super-input_controller.js
import { Controller } from "stimulus";
class Input extends Controller {
static targets = ["parent"]
connect() {
console.log("the value of parentTarget : ", this.parentTarget.value)
}
}
export default class extends Input {
static targets = ["children"]
connect() {
super.connect();
console.log("the value of childrenTarget : ", this.childrenTarget.value)
}
}
The Html
<div data-controller="super-input">
<input type="text"
value="children target"
data-target="super-input.children">
<input type="text"
value="parent target"
data-target="super-input.parent">
</div>
As a result in my console.log I have both targets values available 🎉
the value of parentTarget : parent target
the value of childrenTarget : children target
from tailwindcss-stimulus-components.
Sweet, I didn't even try that, assuming it would replace the value. That looks like it does the trick.
from tailwindcss-stimulus-components.
Related Issues (20)
- Permit use Turbo frame on tabs click -Possible solution- HOT 3
- Multiple modals HOT 1
- How to utlize `cb`?
- https://registry.yarnpkg.com/tailwindcss-stimulus-components~: Not found HOT 1
- - delete this is just an error
- Tabs not working with the select / dropdown HOT 1
- Navigable Tabs with Keyboard HOT 1
- New release? HOT 4
- Active tabs styling is broken in version 4 HOT 2
- Modal forced to the hidden state when added to the DOM HOT 4
- Specify prefix for tailwind classes HOT 2
- Issue when using `data-tabs-update-anchor-value="true"` and linking to a specific anchor from another page HOT 1
- Dropdown improvements HOT 4
- Google Chrome Autofill Result Select Causes Modal Close HOT 3
- Multiple modals on a page -- components not properly behind background HOT 1
- Uncaught (in promise) DOMException: The user aborted a request. HOT 1
- CDN Minified version does not appear to respect `data-toggle-class` for toggle HOT 2
- Toggle feature cannot have multiple divs to have different status
- new release
- Dropdown transition are not working
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tailwindcss-stimulus-components.