forked from folio-org/stripes-components
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMultiSelectFilterField.js
More file actions
82 lines (76 loc) · 2.07 KB
/
Copy pathMultiSelectFilterField.js
File metadata and controls
82 lines (76 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import React from 'react';
import PropTypes from 'prop-types';
import css from './MultiSelect.css';
class MultiSelectFilterField extends React.Component {
static propTypes = {
ariaLabelledBy: PropTypes.string,
atSmallMedia: PropTypes.bool,
backspaceDeletes: PropTypes.bool,
disabled: PropTypes.bool,
getInputProps: PropTypes.func,
inputRef: PropTypes.object,
internalChangeCallback: PropTypes.func,
onBlur: PropTypes.func,
onFocus: PropTypes.func,
onRemove: PropTypes.func,
optionsLength: PropTypes.number,
placeholder: PropTypes.string,
removeItem: PropTypes.func,
selectedItems: PropTypes.oneOfType([
PropTypes.string,
PropTypes.arrayOf(PropTypes.string),
PropTypes.arrayOf(PropTypes.object)
]),
setHighlightedIndex: PropTypes.func,
}
handleInputKeyDown = (event) => {
const {
atSmallMedia,
internalChangeCallback,
removeItem,
onRemove,
optionsLength,
selectedItems,
} = this.props;
if (event.keyCode === 8 && event.target.value.length === 0) { // backspace
if (this.props.backspaceDeletes && !atSmallMedia) {
removeItem(selectedItems[selectedItems.length - 1], internalChangeCallback);
onRemove(selectedItems[selectedItems.length - 1]);
}
}
if (event.keyCode === 36) { // Home
this.props.setHighlightedIndex(0);
}
if (event.keyCode === 35) { // End
this.props.setHighlightedIndex(optionsLength - 1);
}
}
render() {
const {
ariaLabelledBy,
getInputProps,
onFocus,
onBlur,
placeholder,
inputRef,
disabled,
...rest
} = this.props;
return (
<input
{...getInputProps({
'aria-labelledby': rest['aria-labelledby'] || ariaLabelledBy,
'type': 'text',
'ref': inputRef,
'onKeyDown': this.handleInputKeyDown,
onFocus,
onBlur,
placeholder,
'className': css.multiSelectFilterField,
disabled,
})}
/>
);
}
}
export default MultiSelectFilterField;