Sorry, but you either have no stories or none are selected somehow.
If the problem persists, check the browser console, or the terminal you've run Storybook from.
The component failed to render properly, likely due to a configuration issue in Storybook. Here are some common causes and how you can address them:
The primary way that the components communicate with the containing page is by dispatching javascript events. Interacting with them is as easy as listening for events like you do for any standard HTML component
To listen for an event, attach an event listener:
<dt-text id="my-text-input" name="my-text"></dt-text> <script> function myEventListener(evt) { console.log(evt); } document.getElementById('my-text-input').addEventListener('event-name', myEventListener); </script>
A standard event for all of the form components is the change event. This gets triggered any time the value of a form component changes.
Let's take a look at the text field to see how you might use it.
<dt-text id="my-text-input" name="my-text"></dt-text> <script> function onChange(evt) { const detail = evt.detail; console.log(`input with name '${detail.field}' was changed to '${detail.newValue}`); // here is where you can fire an API request to save this value } document.getElementById('my-text-input').addEventListener('change', onChange); </script>
All of the Event
objects that are passed to the event listener will contain a detail
property
that has all of the data relevant to that event.
For this change
event, the Event
would have values like this:
{ "type": "change", "detail": { "field": "my-text", "oldValue": "", "newValue": "[what the user typed]" }, [...] }