extensions/amp-selector/0.1/amp-selector.md
The AMP selector is a control that presents a list of options and lets the user choose one or many options; the contents of the options aren't just limited to text.
amp-selector can contain any arbitrary HTML elements or AMP components (e.g., amp-carousel, amp-img, etc.).amp-selector cannot contain any nested amp-selector controls.option attribute to the element and assigning a value to the attribute (e.g., <li option='value'></li>).disabled attribute to the element (e.g., <li option='d' disabled></li>).selected attribute to the element (e.g., <li option='b' selected></li>).multiple attribute to the amp-selector element. By default, the amp-selector allows for one selection at a time.amp-selector, add the disabled attribute to the amp-selector element.amp-selector contains a name attribute and the amp-selector is inside a form tag, if a submit event occurs on the form, the amp-selectorbehaves like a radio-button/checkbox group and submits the selected values (the ones assigned to the option) against the name of the amp-selector.Example:
<form action="/" method="get" target="_blank" id="form1">
<amp-selector layout="container" name="single_image_select">
<ul>
<li>
<amp-img src="/img1.png" width="50" height="50" option="1"></amp-img>
</li>
<li>
<amp-img src="/img2.png" width="50" height="50" option="2"></amp-img>
</li>
<li option="na" selected>None of the Above</li>
</ul>
</amp-selector>
<amp-selector layout="container" name="multi_image_select" multiple>
<amp-img src="/img1.png" width="50" height="50" option="1"></amp-img>
<amp-img src="/img2.png" width="50" height="50" option="2"></amp-img>
<amp-img src="/img3.png" width="50" height="50" option="3"></amp-img>
</amp-selector>
<amp-selector layout="container" name="multi_image_select_1" multiple>
<amp-carousel id="carousel-1" width="200" height="60" controls>
<amp-img src="/img1.png" width="80" height="60" option="a"></amp-img>
<amp-img
src="/img2.png"
width="80"
height="60"
option="b"
selected
></amp-img>
<amp-img src="/img3.png" width="80" height="60" option="c"></amp-img>
<amp-img
src="/img4.png"
width="80"
height="60"
option="d"
disabled
></amp-img>
</amp-carousel>
</amp-selector>
</form>
<amp-selector
layout="container"
name="multi_image_select_2"
multiple
form="form1"
>
<amp-carousel id="carousel-1" width="400" height="300" type="slides" controls>
<amp-img src="/img1.png" width="80" height="60" option="a"></amp-img>
<amp-img
src="/img2.png"
width="80"
height="60"
option="b"
selected
></amp-img>
<amp-img src="/img3.png" width="80" height="60" option="c"></amp-img>
<amp-img src="/img4.png" width="80" height="60" option="d"></amp-img>
</amp-carousel>
</amp-selector>
To clear all selections when an element is tapped or clicked, set the on action attribute on the element, and specify the AMP Selector id with the clear action method.
Example:
<button on="tap:mySelector.clear">Clear Selection</button>
<amp-selector id="mySelector" layout="container" multiple>
<div option>Option One</div>
<div option>Option Two</div>
<div option>Option Three</div>
</amp-selector>
{% call callout('Tip', type='success') %} See live demos at AMP By Example. {% endcall %}
<amp-selector>The attributes above behave the same way as they do on a standard HTML <select> element.
The keyboard-select-mode attribute dictates the keyboard navigation behavior for options inside <amp-selector>.
<amp-selector> optionsIndicates that the option is selectable. If a value is specified, the contents of the value is submitted with the form.
The attributes above behave the same way as they do on a standard HTML <option> element.
Events may trigger actions on other AMP components using the on attribute.
e.g. on="select: my-tab.show"
Read more about AMP Actions and Events.
amp-selector triggers the select event when the user selects an option.
Multi-selectors and single-selectors fire this when selecting or unselecting options.
Tapping disabled options does not trigger the select event.
See amp-selector rules in the AMP validator specification.