diff --git a/components/aside/index.cjsx b/components/aside/index.cjsx index 31842157..d5695966 100644 --- a/components/aside/index.cjsx +++ b/components/aside/index.cjsx @@ -7,7 +7,7 @@ module.exports = React.createClass active : React.PropTypes.bool className : React.PropTypes.string hideable : React.PropTypes.bool - type : React.PropTypes.string.required + type : React.PropTypes.string getDefaultProps: -> className : "" diff --git a/components/autocomplete/index.cjsx b/components/autocomplete/index.cjsx index 1340fc6b..3fb346c3 100644 --- a/components/autocomplete/index.cjsx +++ b/components/autocomplete/index.cjsx @@ -7,7 +7,7 @@ module.exports = React.createClass propTypes: className : React.PropTypes.string colors : React.PropTypes.object - dataSource : React.PropTypes.object + dataSource : React.PropTypes.any disabled : React.PropTypes.bool error : React.PropTypes.string exact : React.PropTypes.bool @@ -16,7 +16,7 @@ module.exports = React.createClass onChange : React.PropTypes.func required : React.PropTypes.bool type : React.PropTypes.string - value : React.PropTypes.string + value : React.PropTypes.any getDefaultProps: -> className : "" @@ -52,8 +52,17 @@ module.exports = React.createClass @setState focus: false if Object.keys(suggestions).length is 0 onKeyPress: (event) -> + key_ascii = event.which query = @refs.input.getValue().trim() - if event.which is 13 and query isnt "" + + if @state.focus + children = @refs.suggestions.getDOMNode().children + for child, index in children when child.classList.contains "active" + child.classList.remove "active" + query = child.getAttribute "id" + break + + if key_ascii is 13 and query isnt "" for key, label of @state.suggestions when query.toLowerCase() is label.toLowerCase() suggestion = {"#{key}": label} break @@ -62,6 +71,13 @@ module.exports = React.createClass else if suggestion @_addValue suggestion + else if @state.focus and key_ascii in [40, 38] + if key_ascii is 40 + index = if index >= children.length - 1 then 0 else index + 1 + else + index = if index is 0 then children.length - 1 else index - 1 + children[index].classList.add "active" + onBlur: (event) -> setTimeout (=> @setState focus: false, suggestions: {}), 300 @@ -69,6 +85,12 @@ module.exports = React.createClass key = event.target.getAttribute "id" @_addValue {"#{key}": @state.suggestions[key]} + onRefreshSelection: (event) -> + children = @refs.suggestions.getDOMNode().children + for child, index in children when child.classList.contains "active" + child.classList.remove "active" + break + onDelete: (event) -> delete @state.values[event.target.getAttribute "id"] @setState focus: false, values: @state.values @@ -76,21 +98,27 @@ module.exports = React.createClass # -- Render render: -> -
+ className = "focus" if @state.focus +
+ {  if @props.label } { if @props.multiple } - -
diff --git a/components/autocomplete/style.styl b/components/autocomplete/style.styl index 087e6720..e6628385 100644 --- a/components/autocomplete/style.styl +++ b/components/autocomplete/style.styl @@ -2,9 +2,10 @@ [data-component-autocomplete] position : relative - // -- Children + > label + font-size : FONT_SIZE_TINY + color : PRIMARY > [data-role] > * - font-size : FONT_SIZE_SMALL cursor : pointer > [data-role="values"] > * @@ -13,28 +14,33 @@ padding : (SPACE / 4) (SPACE / 2) font-size : FONT_SIZE_SMALL color : WHITE - background-color : THEME + background-color : PRIMARY border-radius : (SPACE / 8) > [data-role="suggestions"] - z-index : 10 + z-index : 2 position : absolute width : 100% + height : 0 + max-height : 50vh overflow-x : hidden overflow-y : scroll - max-height : 0 margin-top : -(SPACE) background-color : WHITE - visibility : hidden - box-shadow : ZDEPTH_SHADOW_1 - transition max-height ANIMATION_DURATION ANIMATION_EASE + opacity : 0 + transform translateY(-(INPUT_HEIGHT / 2)) + transition-property height, box-shadow, opacity, transform + transition-duration ANIMATION_DURATION + transition-timing-function ANIMATION_EASE > * padding : (SPACE / 2) - &:hover + &:hover, &.active color : WHITE - background-color : THEME + background-color : PRIMARY_LIGHT // -- Styles &.focus > [data-role="suggestions"] - max-height : 25vh - visibility : visible + height : auto + opacity : 1 + transform translateY(0%) + box-shadow ZDEPTH_SHADOW_1 diff --git a/components/button/button.md b/components/button/button.md index 25aa1fbc..86b55d23 100644 --- a/components/button/button.md +++ b/components/button/button.md @@ -5,12 +5,12 @@ var Button = require('react-toolbox/components/button');