- With the select element using an opacity of zero (0), the element can have a custom background, and when clicking on the element the hidden select box still behaves normally (browser's default behavior)
- The element with the class
.faux-select-selected
needs javascript functionality which updates the content binding to the value that is selected using the invisble select box (on change).
(clone the emberjs/starter-kit to get started, see the components branch on this clone of starter kit...https://github.com/Ember-SC/starter-kit/commits/components)
- Start with removing the default index template/model from the emberjs/starter-kit
- Add a component template with a select box
- Use model for collection of choices
- Add some attributes and choices
- Scaffold markup and styles for faux select w/ zero opacity
- Add some custom style for the faux select box
- Bind the selected value and set min widths
- https://github.com/Ember-SC/starter-kit
- http://emberjs.com/guides/components/
- http://emberjs.com/api/classes/Ember.Select.html
- http://cssfontstack.com
- http://www.polymer-project.org/platform/custom-elements.html
- https://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/custom/index.html
- http://mozilla.github.io/brick/
Below is a list of required styles for an example faux select box.
- The
select
element has zero (0) opacity and is positionedabsolute
- The
.faux-select-box
element is also positionedabsolute
- The above two elements are siblings as the select box follows the faux element resulting in a higher z-index value, so when user clicks the event is fired on the invisble select box
- the dimensions of the select box and faux select box need to match so the invisble element can be used on top of the faux element
/* FauxSelectComponent */
select.faux-select {
display: block;
opacity: 0;
position: absolute;
height: 20px;
width: 125px;
margin: 5px;
}
.faux-select {
position: relative;
}
.faux-select-box {
position: absolute;
min-width: 137px;
}
.faux-select-selected,
.faux-select-graphic {
height: 17px;
}
.faux-select-selected {
float: left;
min-width: 117px;
padding: 5px 10px;
}
.faux-select-graphic {
float: right;
padding: 5px 7px;
}
- Native browser support for select/dropdown behavior including arrow keys, typing to select an option
- Mobile devices still use finger friendly behaviour for select behaviors
- Screen readers behave as expected with a standard select box
- You don't have to fix all the bugs for taking over all the native brower support listed above and the custom select box can now match the designers branding needs
The code in this example select box component has not been tested in various browsers and cross-browser css has not been included in the demo code. The concept of using 0 opacity for the selectbox does work in modern browsers.