diff --git a/examples/selector.amp.html b/examples/selector.amp.html new file mode 100644 index 0000000000000..84a07ef95cd7d --- /dev/null +++ b/examples/selector.amp.html @@ -0,0 +1,59 @@ + + + + + + AMP Selector Demo + + + + + + +

Selector Examples

+

Single Select

+ + + + +

Multi Select

+ + + + +

Actions

+ + + + + + + + + + + + diff --git a/extensions/amp-selector/0.1/amp-selector.js b/extensions/amp-selector/0.1/amp-selector.js index 9b77d4b7e3b6b..044655388553b 100644 --- a/extensions/amp-selector/0.1/amp-selector.js +++ b/extensions/amp-selector/0.1/amp-selector.js @@ -396,7 +396,10 @@ export class AmpSelector extends AMP.BaseElement { // There is a change of the `selected` attribute for the element if (selectedIndex !== index) { this.setSelection_(el); - this.clearSelection_(this.elements_[selectedIndex]); + const selectedEl = this.elements_[selectedIndex]; + if (selectedEl) { + this.clearSelection_(selectedEl); + } } else { this.clearSelection_(el); } @@ -435,7 +438,10 @@ export class AmpSelector extends AMP.BaseElement { const normalizedIndex = mod(index, this.elements_.length); this.setSelection_(this.elements_[normalizedIndex]); - this.clearSelection_(this.elements_[previousIndex]); + const previousEl = this.elements_[previousIndex]; + if (previousEl) { + this.clearSelection_(previousEl); + } } /**