Skip to content

Commit

Permalink
docs(demo): fix the selector for the demo added back in #55
Browse files Browse the repository at this point in the history
  • Loading branch information
jason-capsule42 committed Mar 29, 2022
1 parent 0b1f4d0 commit 168f3d6
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 5 deletions.
4 changes: 2 additions & 2 deletions demo/alertValue.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
setTimeout(() => {
document.querySelector('#valueExtraction').addEventListener('selectedOption', () => {
const menu = document.querySelector('#valueExtraction auro-menu');
document.querySelector('#valueAlert').addEventListener('selectedOption', () => {
const menu = document.querySelector('#valueAlert auro-menu');
console.warn('Value selected:', menu.optionSelected.value);
alert(`Value selected: ${menu.optionSelected.value}`);
});
Expand Down
63 changes: 60 additions & 3 deletions demo/apiExamples.md
Original file line number Diff line number Diff line change
Expand Up @@ -390,10 +390,15 @@ The following example illustrates how a user may query the `.value` of the `auro
* @param {string} Selector for auro-select to retrieve the value from.
*/
const getValue = (selector) => {
const el = document.querySelector(selector);
const menu = document.querySelector(`${selector} auro-menu`);

console.warn(el.value);
alert(el.value);
if (menu.optionSelected) {
console.warn('Value selected:', menu.optionSelected.value);
alert(`Value selected: ${menu.optionSelected.value}`);
} else {
console.warn('Value selected:', null);
alert(`Value selected: ${null}`);
}
}
```
<!-- AURO-GENERATED-CONTENT:END -->
Expand All @@ -414,4 +419,56 @@ const getValue = (selector) => {
<auro-button onclick="getValue('#valueExtraction');">Get current value</auro-button>
```
<!-- AURO-GENERATED-CONTENT:END -->
</auro-accordion>

### Watch for value changes

The following example listens for the `selectOption` custom event from the `<auro-menu>` APi. Once triggered, the custom event will return an object `{value: any}`.

<div class="exampleWrapper">
<!-- AURO-GENERATED-CONTENT:START (FILE:src=./../../apiExamples/valueAlert.html) -->
<!-- The below content is automatically added from ./../../apiExamples/valueAlert.html -->
<auro-select id="valueAlert">
<auro-menu>
<auro-menuoption value="stops">Stops</auro-menuoption>
<auro-menuoption value="price">Price</auro-menuoption>
<auro-menuoption value="duration">Duration</auro-menuoption>
<auro-menuoption value="departure">Departure</auro-menuoption>
<auro-menuoption value="arrival">Arrival</auro-menuoption>
<auro-menuoption value="prefer alaska">Prefer Alaska</auro-menuoption>
</auro-menu>
</auro-select>
<!-- AURO-GENERATED-CONTENT:END -->
</div>
<auro-accordion lowProfile justifyRight>
<span slot="trigger">See code</span>
<!-- AURO-GENERATED-CONTENT:START (CODE:src=./../../demo/alertValue.js) -->
<!-- The below code snippet is automatically added from ./../../demo/alertValue.js -->

```js
setTimeout(() => {
document.querySelector('#valueAlert').addEventListener('selectedOption', () => {
const menu = document.querySelector('#valueAlert auro-menu');
console.warn('Value selected:', menu.optionSelected.value);
alert(`Value selected: ${menu.optionSelected.value}`);
});
}, 500);
```
<!-- AURO-GENERATED-CONTENT:END -->
<!-- AURO-GENERATED-CONTENT:START (CODE:src=./../../apiExamples/valueAlert.html) -->
<!-- The below code snippet is automatically added from ./../../apiExamples/valueAlert.html -->

```html
<auro-select id="valueAlert">
<auro-menu>
<auro-menuoption value="stops">Stops</auro-menuoption>
<auro-menuoption value="price">Price</auro-menuoption>
<auro-menuoption value="duration">Duration</auro-menuoption>
<auro-menuoption value="departure">Departure</auro-menuoption>
<auro-menuoption value="arrival">Arrival</auro-menuoption>
<auro-menuoption value="prefer alaska">Prefer Alaska</auro-menuoption>
</auro-menu>
</auro-select>
```
<!-- AURO-GENERATED-CONTENT:END -->
</auro-accordion>

0 comments on commit 168f3d6

Please sign in to comment.