Skip to content

Commit

Permalink
Use full Toolbox input in autocomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
javivelasco committed Dec 20, 2015
1 parent 2c7d308 commit 802f50f
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 27 deletions.
16 changes: 11 additions & 5 deletions components/autocomplete/Autocomplete.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ class Autocomplete extends React.Component {
query: this.query(this.props.value)
};

componentWillReceiveProps (nextProps) {
if (!this.props.multiple) {
this.setState({query: nextProps.value});
}
}

shouldComponentUpdate (nextProps, nextState) {
if (!this.state.focus && nextState.focus && this.props.direction === POSITION.AUTO) {
const direction = this.calculateDirection();
Expand Down Expand Up @@ -171,20 +177,20 @@ class Autocomplete extends React.Component {
}

render () {
const {error, label, ...other} = this.props;
const className = ClassNames(style.root, {
[style.focus]: this.state.focus,
[style.errored]: this.props.error
[style.focus]: this.state.focus
}, this.props.className);

return (
<div data-react-toolbox='autocomplete' className={className}>
{this.props.label ? <label className={style.label}>{this.props.label}</label> : null}
{this.renderSelected()}
<Input
{...other}
ref='input'
{...this.props}
className={style.input}
label=''
error={error}
label={label}
onBlur={this.handleQueryBlur}
onChange={this.handleQueryChange}
onFocus={this.handleQueryFocus}
Expand Down
1 change: 0 additions & 1 deletion components/autocomplete/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class AutocompleteTest extends React.Component {
direction="down"
label="Choose countries"
onChange={this.handleChange}
placeholder="Pick multiple elements..."
source={source}
value={this.state.value}
/>
Expand Down
24 changes: 16 additions & 8 deletions components/autocomplete/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@
box-shadow: $zdepth-shadow-1;
}
}
&.errored {
.suggestions {
margin-top: - $input-underline-height;
}
}
}

.label {
Expand Down Expand Up @@ -59,7 +54,7 @@
transition-duration: $animation-duration;
transition-property: max-height, box-shadow;
&:not(.up) {
bottom: auto;
margin-top: - $input-padding;
}
&.up {
bottom: 0;
Expand All @@ -75,6 +70,19 @@
}

.input {
padding-top: 0;
padding-bottom: 0;
position: relative;
&:after {
$size: ($input-field-height / 7);
$border: $size solid transparent;
position: absolute;
top: 50%;
right: $input-chevron-offset;
width: 0;
height: 0;
content: "";
border-top: $size solid $input-text-bottom-border-color;
border-right: $border;
border-left: $border;
transition: transform $animation-duration $animation-curve-default;
}
}
1 change: 0 additions & 1 deletion components/dropdown/_config.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
$dropdown-offset: 1.6 * $unit;
$dropdown-color-white: $color-white;
$dropdown-color-primary: $color-primary;
$dropdown-color-primary-contrast: $color-primary-contrast;
Expand Down
18 changes: 9 additions & 9 deletions components/dropdown/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
$size: ($input-field-height / 7);
$border: $size solid transparent;
position: absolute;
right: ($dropdown-offset / 2);
top: 50%;
right: $input-chevron-offset;
width: 0;
height: 0;
content: "";
Expand All @@ -67,31 +67,31 @@
}
}
&.disabled {
cursor: normal;
pointer-events: none;
cursor: normal;
> .templateValue {
opacity: .7;
border-bottom-style: dotted;
opacity: .7;
}
}
}

.templateValue {
border-bottom: 1px solid $input-text-bottom-border-color;
color: $color-text;
position: relative;
min-height: $input-field-height;
background-color: $input-text-background-color;
padding: $input-field-padding 0;
position: relative;
color: $color-text;
background-color: $input-text-background-color;
border-bottom: 1px solid $input-text-bottom-border-color;
}

.label {
position: absolute;
top: $input-focus-label-top;
left: 0;
font-size: $input-label-font-size;
line-height: $input-field-font-size;
color: $input-text-label-color;
top: $input-focus-label-top;
}

.error {
Expand All @@ -103,8 +103,8 @@

.values {
@include no-webkit-scrollbar;
z-index: $z-index-high;
position: absolute;
z-index: $z-index-high;
width: 100%;
overflow-y: auto;
list-style: none;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class AutocompleteTest extends React.Component {
label="Choose countries"
name="countries"
onChange={this.handleChange}
placeholder="Pick multiple elements..."
source={source}
value={this.state.countries}
/>
Expand Down
3 changes: 1 addition & 2 deletions spec/components/autocomplete.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ class AutocompleteTest extends React.Component {
<p>You can have a multiple or simple autocomplete.</p>

<Autocomplete
label="Choose countries"
onChange={this.handleMultipleChange}
placeholder="Pick multiple elements..."
label="Pick multiple elements..."
source={countriesObject}
value={this.state.multiple}
/>
Expand Down

0 comments on commit 802f50f

Please sign in to comment.