Skip to content
This repository has been archived by the owner on Jan 31, 2024. It is now read-only.

Commit

Permalink
0.6.3 - Fix isMultiple SelectInput
Browse files Browse the repository at this point in the history
  • Loading branch information
jducro committed Nov 16, 2018
1 parent 37ff3fe commit 0d5ad87
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.6.3 - 2018-11-16

* Fix SelectInput isMultiple keyboard selection

## 0.6.2 - 2018-11-09

* Update `react-components` to `1.4.1`
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@deskpro/token-field",
"version": "0.6.2",
"version": "0.6.3",
"description": "",
"main": "dist/index.js",
"private": false,
Expand Down
3 changes: 0 additions & 3 deletions src/Components/Input/DateTimeInput.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,11 @@ export default class DateTimeInput extends TokenInput {
}

onFocus = () => {
console.log('focus');
this.props.onFocus();
window.document.addEventListener('keydown', this.handleKeyDown);
};

onBlur = () => {
console.log('blur');
this.props.onBlur();
window.document.removeEventListener('keydown', this.handleKeyDown);
};
Expand Down Expand Up @@ -161,7 +159,6 @@ export default class DateTimeInput extends TokenInput {
};

handleKeyDown = (e) => {
console.log(e.key);
switch (e.key) {
case 'ArrowDown':
case 'ArrowUp': {
Expand Down
24 changes: 21 additions & 3 deletions src/Components/Input/SelectInput.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,19 @@ export default class SelectInput extends TokenInput {
this.disableEditMode();
break;
case ' ':
if (this.props.isMultiple) {
const { selectedOption, value } = this.state;
const key = selectedOption.id || selectedOption.value;
let checked = false;
if (value) {
checked = value.indexOf(key) !== -1;
}
this.handleChangeMultiple(!checked, key);
} else {
this.handleChange(this.state.selectedOption);
this.props.selectNextToken();
}
break;
case 'Enter':
this.handleChange(this.state.selectedOption);
this.props.selectNextToken();
Expand Down Expand Up @@ -260,7 +273,11 @@ export default class SelectInput extends TokenInput {
return renderHeader;
};

renderLoading = () => <ListElement className={styles.loading}><Icon name={faSpinner} size="large" spin /></ListElement>;
renderLoading = () => (
<ListElement className={styles.loading}>
<Icon name={faSpinner} size="large" spin />
</ListElement>
);


renderOptions = () => {
Expand Down Expand Up @@ -298,7 +315,7 @@ export default class SelectInput extends TokenInput {
};

renderMultipleOptions() {
const { filter, value, loading } = this.state;
const { filter, value, loading, selectedOption } = this.state;
let options;
if (loading) {
return this.renderLoading();
Expand All @@ -313,14 +330,15 @@ export default class SelectInput extends TokenInput {
return (options
.map((option) => {
const key = option.id || option.value;
const selected = option === selectedOption ? styles.selected : '';
let checked = false;
if (value) {
checked = value.indexOf(key) !== -1;
}
return (
<ListElement
key={key}
className={styles.option}
className={this.cx(styles.option, selected, 'option')}
>
<Checkbox checked={checked} value={key} onChange={this.handleChangeMultiple}>
{this.renderItem(option)}
Expand Down
6 changes: 5 additions & 1 deletion src/Components/TokenField.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export default class TokenField extends React.Component {
};

this.inputs = [];
this.inputField = null;
}

componentWillReceiveProps(nextProps) {
Expand Down Expand Up @@ -82,6 +83,9 @@ export default class TokenField extends React.Component {
if (this.pendingBlur) {
window.clearTimeout(this.pendingBlur);
}
if (this.inputField) {
this.inputField.closePopper();
}
this.pendingBlur = window.setTimeout(() => {
this.setState({
focused: false
Expand All @@ -92,7 +96,7 @@ export default class TokenField extends React.Component {

getInputField = (key, value) => (
<TokenFieldInput
ref={(c) => { this.inputs[key] = c; }}
ref={(c) => { this.inputs[key] = c; this.inputField = c; }}
value={value}
key={key}
tokenKey={key}
Expand Down
16 changes: 14 additions & 2 deletions tests/storybook/components/TokenField.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ const tokenTypes = [
}
},
{
id: 'country',
id: 'country-async',
widget: 'SelectInput',
props: {
dataSource: {
Expand All @@ -117,6 +117,18 @@ const tokenTypes = [
showSearch: false
},
},
{
id: 'country',
widget: 'SelectInput',
props: {
dataSource: {
getOptions: countries
},
renderHeader: <h3>Countries</h3>,
showSearch: false,
isMultiple: true,
},
},
{
id: 'user-waiting',
widget: 'DurationInput',
Expand All @@ -136,7 +148,7 @@ const defaultValue = [
},
{
type: 'country',
value: 'GB',
value: ['GB'],
meta: [
{ label: 'United Kingdom', value: 'GB' }
],
Expand Down
4 changes: 3 additions & 1 deletion tests/storybook/components/input/SelectInput.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ storiesOf('Inputs', module)
className="test"
/>
<SelectInput
dataSource={{ getOptions: () => fakeAPI('', 30000, optionsWithIcon), findOptions: filter => fakeAPI(filter, 30000, optionsWithIcon) }}
dataSource={{ getOptions: () =>
fakeAPI('', 30000, optionsWithIcon),
findOptions: filter => fakeAPI(filter, 30000, optionsWithIcon) }}
token={selectTokenIcon}
label="temperature"
selectPreviousToken={action('SelectPreviousToken')}
Expand Down

0 comments on commit 0d5ad87

Please sign in to comment.