amp-selector is an AMP Extended Component that presents a list of options and lets the user choose one or many options.
You can see a demo of this component in action on AMP By Example website.
Currently there is no way to clear the selection in a single or multi-select amp-selector. This is a useful feature and we like to expose it as an AMP Action on the component, for instance we like to support the following code:
<button on="tap:mySelector.clear">Clear Selection</button>
<amp-selector id="mySelector" layout="container" multiple>
<div>Option One</div>
<div>Option Two</div>
<div>Option Three</div>
<div>Option Four</div>
</amp-selector>
amp-selector already has private methods for clearing selection, we just need to expose them as an action, test and document it.
clear using this.registerAction method inside amp-selector.js clearAllSelections_ method.test-amp-selector.jsamp-selector.md to document the new feature.closes Issue #10475 in the description.Once approved, your changes will be merged. ⚡⚡⚡Congrats on making your first contribution to the AMP Project!⚡⚡⚡ You'll be able to see it live across the web soon!
Thanks, and we hope to see more contributions from you soon.
If you have questions ask in this issue or on your Pull Request (mentioning @aghassemi) or see the How to get help section of the Getting Started guide.
I want to try out implementing this as my first open source contribution, could I claim it?
@mianuddin Go for it, thanks for contributing.
@aghassemi What's the best way to go about testing the action? I went through the tests for other extensions but could not find a similar instance for reference.
@mianuddin For a good e2e test:
getSelector to create a multi-select amp-selector similar to other tests but also pass an id in the attributes button (using win.document.createElement) and set it's on attribute to call the selector's clear action ( similar to the sample code ). win.bodybtn.click() will do)selected attribute now don't have it anymore.Sounds great! I'll try it out right now. I have most of that already done, but I was working with TriggerSpy based on what I saw in other tests. Thanks for the clear breakdown!
@aghassemi I just made both of my pull requests. It won't allow me to add you as a reviewer, so I mentioned you in the comments.
@aghassemi, @mianuddin
Good addition to AMP:)
We need to clear other amp-selectors if one has a selection. Only one PARENT is allowed to be selected. They are the same radio "name" that solves it. We need only the amp-selector chosen under the selected PARENT radio that is chosen. The amp-selectors under the others need to be cleared. Ugh. Customer is able to select one of OPTION3, then select one of OPTION2. Both stay selected. Cannot bind [clear] on See https://codepen.io/iamalta/pen/WJbypN Any thoughts on that?
Console error: "amp-bind: Binding to [clear] on
Ditto for
Most helpful comment
@aghassemi I just made both of my pull requests. It won't allow me to add you as a reviewer, so I mentioned you in the comments.