@hipay/hipay-material-ui 2.0.0-beta.76 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +77 -0
- package/HiDatePicker/HiDatePicker.js +0 -4
- package/HiExpansionPanel/HiExpansionPanel.js +19 -10
- package/HiForm/index.js +17 -1
- package/HiNotice/HiKPI.js +13 -9
- package/HiPaymentMeans/HiPaymentMeans.js +36 -32
- package/HiSelect/HiSelect.js +49 -51
- package/HiSelect/HiSuggestSelect.js +62 -54
- package/HiSelectableList/HiSelectableList.js +28 -9
- package/HiSelectableList/HiSelectableListItem.js +1 -1
- package/README.md +2 -2
- package/es/HiDatePicker/HiDatePicker.js +0 -2
- package/es/HiExpansionPanel/HiExpansionPanel.js +19 -10
- package/es/HiForm/index.js +3 -1
- package/es/HiNotice/HiKPI.js +14 -9
- package/es/HiPaymentMeans/HiPaymentMeans.js +34 -32
- package/es/HiSelect/HiSelect.js +30 -27
- package/es/HiSelect/HiSuggestSelect.js +61 -52
- package/es/HiSelectableList/HiSelectableList.js +26 -8
- package/es/HiSelectableList/HiSelectableListItem.js +1 -1
- package/index.es.js +1 -1
- package/index.js +1 -1
- package/package.json +1 -1
@@ -41,7 +41,8 @@ class HiSuggestSelect extends React.PureComponent {
|
|
41
41
|
static getDerivedStateFromProps(props, state) {
|
42
42
|
if (JSON.stringify(props.options) !== JSON.stringify(state.options)) {
|
43
43
|
return {
|
44
|
-
options: props.options
|
44
|
+
options: props.options,
|
45
|
+
suggestionFocusIndex: -1
|
45
46
|
};
|
46
47
|
}
|
47
48
|
|
@@ -51,6 +52,14 @@ class HiSuggestSelect extends React.PureComponent {
|
|
51
52
|
constructor(props) {
|
52
53
|
super(props);
|
53
54
|
|
55
|
+
this.getInputElement = el => {
|
56
|
+
this.textInput = el;
|
57
|
+
|
58
|
+
if (this.props.inputRef) {
|
59
|
+
this.props.inputRef(this.textInput);
|
60
|
+
}
|
61
|
+
};
|
62
|
+
|
54
63
|
this.handleSelect = (event, value) => {
|
55
64
|
document.body.style.overflow = 'auto';
|
56
65
|
this.props.onSelect(event, value);
|
@@ -88,67 +97,65 @@ class HiSuggestSelect extends React.PureComponent {
|
|
88
97
|
};
|
89
98
|
|
90
99
|
this.handleKeyDownSearch = event => {
|
91
|
-
if (event.key === 'ArrowDown'
|
92
|
-
|
100
|
+
if (event.key === 'ArrowDown') {
|
101
|
+
event.preventDefault();
|
93
102
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
103
|
+
if (this.state.suggestionFocusIndex < this.props.options.length - 1) {
|
104
|
+
this.setState(prevState => ({
|
105
|
+
suggestionFocusIndex: prevState.suggestionFocusIndex + 1
|
106
|
+
}));
|
107
|
+
}
|
108
|
+
} else if (event.key === 'ArrowUp') {
|
109
|
+
event.preventDefault();
|
98
110
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
}
|
103
|
-
}
|
111
|
+
if (this.state.suggestionFocusIndex >= 0) {
|
112
|
+
this.setState(prevState => ({
|
113
|
+
suggestionFocusIndex: prevState.suggestionFocusIndex - 1
|
114
|
+
}));
|
115
|
+
}
|
116
|
+
} else if (event.key === 'Enter' && this.state.suggestionFocusIndex >= 0) {
|
117
|
+
event.preventDefault(); // Suggestion focused
|
118
|
+
|
119
|
+
this.handleSelect(event, this.state.options[this.state.suggestionFocusIndex]);
|
104
120
|
} else if (event.key === 'Escape') {
|
105
121
|
this.setState({
|
106
|
-
options: []
|
122
|
+
options: [],
|
123
|
+
suggestionFocusIndex: -1
|
107
124
|
});
|
108
125
|
}
|
109
126
|
};
|
110
127
|
|
111
|
-
this.
|
112
|
-
focused: false,
|
113
|
-
options: props.options
|
114
|
-
};
|
115
|
-
this.handleSelect = this.handleSelect.bind(this);
|
116
|
-
this.handleBlur = this.handleBlur.bind(this);
|
117
|
-
this.handleFocus = this.handleFocus.bind(this);
|
118
|
-
this.getInputElement = this.getInputElement.bind(this);
|
119
|
-
}
|
120
|
-
|
121
|
-
getInputElement(el) {
|
122
|
-
this.textInput = el;
|
123
|
-
|
124
|
-
if (this.props.inputRef) {
|
125
|
-
this.props.inputRef(this.textInput);
|
126
|
-
}
|
127
|
-
}
|
128
|
-
|
129
|
-
handleFocus(event) {
|
130
|
-
this.setState({
|
131
|
-
focused: true
|
132
|
-
});
|
133
|
-
|
134
|
-
if (this.props.onFocusInput) {
|
135
|
-
this.props.onFocusInput(event);
|
136
|
-
}
|
137
|
-
}
|
138
|
-
|
139
|
-
handleBlur(event) {
|
140
|
-
// Si on click sur un élément de HiInput, on garde le focus
|
141
|
-
// Par exemple sur l'icone reset
|
142
|
-
if (!event.relatedTarget || !this.overlay || !this.overlay.contains(event.relatedTarget)) {
|
128
|
+
this.handleFocus = event => {
|
143
129
|
this.setState({
|
144
|
-
|
145
|
-
focused: false
|
130
|
+
focused: true
|
146
131
|
});
|
147
132
|
|
148
|
-
if (this.props.
|
149
|
-
this.props.
|
133
|
+
if (this.props.onFocusInput) {
|
134
|
+
this.props.onFocusInput(event);
|
150
135
|
}
|
151
|
-
}
|
136
|
+
};
|
137
|
+
|
138
|
+
this.handleBlur = event => {
|
139
|
+
// Si on click sur un élément de HiInput, on garde le focus
|
140
|
+
// Par exemple sur l'icone reset
|
141
|
+
if (!event.relatedTarget || !this.overlay || !this.overlay.contains(event.relatedTarget)) {
|
142
|
+
this.setState({
|
143
|
+
options: [],
|
144
|
+
focused: false,
|
145
|
+
suggestionFocusIndex: -1
|
146
|
+
});
|
147
|
+
|
148
|
+
if (this.props.onBlurInput) {
|
149
|
+
this.props.onBlurInput(event);
|
150
|
+
}
|
151
|
+
}
|
152
|
+
};
|
153
|
+
|
154
|
+
this.state = {
|
155
|
+
focused: false,
|
156
|
+
options: props.options,
|
157
|
+
suggestionFocusIndex: -1
|
158
|
+
};
|
152
159
|
}
|
153
160
|
|
154
161
|
render() {
|
@@ -168,7 +175,8 @@ class HiSuggestSelect extends React.PureComponent {
|
|
168
175
|
|
169
176
|
const {
|
170
177
|
focused,
|
171
|
-
options
|
178
|
+
options,
|
179
|
+
suggestionFocusIndex
|
172
180
|
} = this.state;
|
173
181
|
let optionsShown = options; // If loading
|
174
182
|
|
@@ -230,7 +238,8 @@ class HiSuggestSelect extends React.PureComponent {
|
|
230
238
|
hideCheckbox: true,
|
231
239
|
onSelect: this.handleSelect,
|
232
240
|
translations: translations,
|
233
|
-
onKeyDown: this.handleKeyDown
|
241
|
+
onKeyDown: this.handleKeyDown,
|
242
|
+
suggestionFocusIndex: suggestionFocusIndex
|
234
243
|
})))));
|
235
244
|
}
|
236
245
|
|
@@ -8,9 +8,14 @@ import HiSelectableListItem from './HiSelectableListItem';
|
|
8
8
|
import { getNextItemSelectable, foldAccents } from '../utils/helpers';
|
9
9
|
import keycode from 'keycode';
|
10
10
|
import LazyLoad, { forceCheck } from 'react-lazyload';
|
11
|
-
|
11
|
+
import classNames from 'classnames';
|
12
|
+
export const styles = theme => ({
|
12
13
|
root: {
|
13
14
|
padding: 0
|
15
|
+
},
|
16
|
+
suggestionFocus: {
|
17
|
+
backgroundColor: theme.palette.action.hover,
|
18
|
+
fontWeight: theme.typography.fontWeightMedium
|
14
19
|
}
|
15
20
|
});
|
16
21
|
/**
|
@@ -44,7 +49,7 @@ class HiSelectableList extends React.PureComponent {
|
|
44
49
|
}
|
45
50
|
};
|
46
51
|
|
47
|
-
this.buildRecursiveListItem = (item, level = 0) => {
|
52
|
+
this.buildRecursiveListItem = (item, index, level = 0) => {
|
48
53
|
const _this$props = this.props,
|
49
54
|
{
|
50
55
|
checkedIcon,
|
@@ -57,9 +62,11 @@ class HiSelectableList extends React.PureComponent {
|
|
57
62
|
selectedItemIdList,
|
58
63
|
sort,
|
59
64
|
onKeyDown,
|
60
|
-
onKeyUp
|
65
|
+
onKeyUp,
|
66
|
+
suggestionFocusIndex,
|
67
|
+
classes
|
61
68
|
} = _this$props,
|
62
|
-
others = _objectWithoutProperties(_this$props, ["checkedIcon", "disabled", "disabledItemIdList", "hideCheckbox", "hoverIcon", "icon", "lazy", "selectedItemIdList", "sort", "onKeyDown", "onKeyUp"]);
|
69
|
+
others = _objectWithoutProperties(_this$props, ["checkedIcon", "disabled", "disabledItemIdList", "hideCheckbox", "hoverIcon", "icon", "lazy", "selectedItemIdList", "sort", "onKeyDown", "onKeyUp", "suggestionFocusIndex", "classes"]);
|
63
70
|
|
64
71
|
if (sort && item.children) {
|
65
72
|
item.children.sort(this.compareItem);
|
@@ -95,8 +102,13 @@ class HiSelectableList extends React.PureComponent {
|
|
95
102
|
onKeyUp: onKeyUp,
|
96
103
|
selected: selectedItemIdList.includes(item.id) // item props override upper props (disabled, hideCheckbox, icon, level...)
|
97
104
|
,
|
98
|
-
item: item
|
99
|
-
|
105
|
+
item: item,
|
106
|
+
classes: {
|
107
|
+
listItem: classNames({
|
108
|
+
[classes.suggestionFocus]: index === suggestionFocusIndex
|
109
|
+
})
|
110
|
+
}
|
111
|
+
}, item)), item.children && item.children.length > 0 && item.children.filter(subItem => !(subItem.displayed === false)).map(subItem => this.buildRecursiveListItem(subItem, index, level + 1)));
|
100
112
|
|
101
113
|
if (lazy) {
|
102
114
|
return React.createElement(LazyLoad, {
|
@@ -188,7 +200,7 @@ class HiSelectableList extends React.PureComponent {
|
|
188
200
|
this.el = el;
|
189
201
|
}
|
190
202
|
}, itemList.filter(item => !(item.displayed === false)) // don't remove if undefined
|
191
|
-
.map(item => this.buildRecursiveListItem(item)));
|
203
|
+
.map((item, index) => this.buildRecursiveListItem(item, index)));
|
192
204
|
}
|
193
205
|
|
194
206
|
}
|
@@ -277,6 +289,11 @@ HiSelectableList.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
277
289
|
*/
|
278
290
|
selectedItemIdList: PropTypes.array,
|
279
291
|
|
292
|
+
/**
|
293
|
+
* Index de l'item "focus"
|
294
|
+
*/
|
295
|
+
suggestionFocusIndex: PropTypes.number,
|
296
|
+
|
280
297
|
/**
|
281
298
|
* Tri des éléments selon leur label
|
282
299
|
*/
|
@@ -294,5 +311,6 @@ HiSelectableList.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
294
311
|
} : {};
|
295
312
|
export default withStyles(styles, {
|
296
313
|
hiComponent: true,
|
297
|
-
name: 'HmuiHiSelectableList'
|
314
|
+
name: 'HmuiHiSelectableList',
|
315
|
+
index: 51
|
298
316
|
})(HiSelectableList);
|
@@ -330,7 +330,7 @@ class HiSelectableListItem extends React.PureComponent {
|
|
330
330
|
indeterminateIcon: indeterminateIcon
|
331
331
|
}), type === 'image' && img && React.createElement("img", {
|
332
332
|
src: img,
|
333
|
-
alt:
|
333
|
+
alt: '',
|
334
334
|
onError: e => {
|
335
335
|
if (fallbackImage) {
|
336
336
|
e.target.src = `${fallbackImage}`;
|
package/index.es.js
CHANGED
package/index.js
CHANGED
package/package.json
CHANGED