@hipay/hipay-material-ui 1.0.0-beta.3 → 1.0.0-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/HiChip/HiChip.js +4 -4
- package/HiColoredLabel/HiColoredLabel.js +1 -1
- package/HiDatePicker/HiDatePicker.js +12 -14
- package/HiDatePicker/HiDateRangeSelector.js +5 -5
- package/HiForm/HiFormControl.js +5 -2
- package/HiForm/HiInput.js +4 -4
- package/HiForm/HiSearchField.js +1 -1
- package/HiSelect/HiSelect.js +286 -258
- package/HiSelect/HiSelectField.js +8 -6
- package/HiSelect/HiSuggestSelect.js +25 -47
- package/HiSelect/HiSuggestSelectField.js +88 -80
- package/HiSelect/SelectInput.js +32 -21
- package/HiSelectableList/HiSelectableList.js +8 -2
- package/HiSelectableList/HiSelectableListItem.js +41 -38
- package/HiTable/HiTable.js +1 -1
- package/HiTable/HiTableFooterScroll.js +1 -1
- package/HiTopBar/HiTopBar.js +16 -12
- package/es/HiChip/HiChip.js +4 -4
- package/es/HiColoredLabel/HiColoredLabel.js +1 -1
- package/es/HiDatePicker/HiDatePicker.js +12 -14
- package/es/HiDatePicker/HiDateRangeSelector.js +5 -5
- package/es/HiForm/HiFormControl.js +5 -2
- package/es/HiForm/HiInput.js +4 -4
- package/es/HiForm/HiSearchField.js +1 -1
- package/es/HiSelect/HiSelect.js +262 -230
- package/es/HiSelect/HiSelectField.js +9 -7
- package/es/HiSelect/HiSuggestSelect.js +24 -39
- package/es/HiSelect/HiSuggestSelectField.js +77 -69
- package/es/HiSelect/SelectInput.js +42 -21
- package/es/HiSelectableList/HiSelectableList.js +9 -3
- package/es/HiSelectableList/HiSelectableListItem.js +41 -38
- package/es/HiTable/HiTable.js +1 -1
- package/es/HiTable/HiTableFooterScroll.js +1 -1
- package/es/HiTopBar/HiTopBar.js +16 -8
- package/es/utils/hiHelpers.js +1 -1
- package/index.es.js +1 -1
- package/index.js +1 -1
- package/package.json +1 -1
- package/umd/hipay-material-ui.development.js +8701 -8705
- package/umd/hipay-material-ui.production.min.js +5 -5
- package/utils/hiHelpers.js +1 -1
package/es/HiSelect/HiSelect.js
CHANGED
@@ -9,11 +9,9 @@ import Grow from 'material-ui/transitions/Grow';
|
|
9
9
|
import { findDOMNode } from 'react-dom';
|
10
10
|
import Paper from 'material-ui/Paper';
|
11
11
|
import ClickAwayListener from 'material-ui/utils/ClickAwayListener';
|
12
|
-
import Collapse from 'material-ui/transitions/Collapse';
|
13
12
|
import { Manager, Target, Popper } from 'react-popper';
|
14
13
|
import { CheckboxBlankOutline, CheckboxMarked } from 'mdi-material-ui';
|
15
14
|
import HiSelectableList from '../HiSelectableList';
|
16
|
-
import HiSelectableListItem from '../HiSelectableList/HiSelectableListItem';
|
17
15
|
import { HiSearchField } from '../HiForm';
|
18
16
|
import SelectInput from './SelectInput';
|
19
17
|
import HiChip from '../HiChip/HiChip';
|
@@ -71,231 +69,7 @@ class HiSelect extends React.PureComponent {
|
|
71
69
|
constructor(props) {
|
72
70
|
super(props);
|
73
71
|
|
74
|
-
|
75
|
-
document.body.style.overflow = 'hidden';
|
76
|
-
this.setState({ open: true });
|
77
|
-
const options = this.props.options.slice();
|
78
|
-
this.handleSuggestions(options);
|
79
|
-
|
80
|
-
if (this.props.onClick) {
|
81
|
-
this.props.onClick();
|
82
|
-
}
|
83
|
-
|
84
|
-
// Gestion du focus
|
85
|
-
if (this.searchField) {
|
86
|
-
// si searchable, focus sur le champs de recherche
|
87
|
-
const searchField = this.searchField;
|
88
|
-
setTimeout(() => {
|
89
|
-
searchField.focus();
|
90
|
-
}, 1);
|
91
|
-
} else if (this.overlay) {
|
92
|
-
// sinon focus sur le dernier élément selectionné
|
93
|
-
this.focusOnSelectedItem();
|
94
|
-
}
|
95
|
-
};
|
96
|
-
|
97
|
-
this.focusOnSelectedItem = () => {
|
98
|
-
// On récupère la div parent "overlay"
|
99
|
-
const overlay = findDOMNode(this.overlay);
|
100
|
-
const multiple = this.props.multiple;
|
101
|
-
const value = this.props.value;
|
102
|
-
const selectedIdList = Array.isArray(value) ? value : [value];
|
103
|
-
setTimeout(() => {
|
104
|
-
let focused = false;
|
105
|
-
// Si un ou plusieurs items sont selectionnés, on focus sur le dernier
|
106
|
-
if (selectedIdList.length > 0) {
|
107
|
-
const itemSelected = overlay.querySelector(`[data-id="${selectedIdList[selectedIdList.length - 1]}"]`);
|
108
|
-
if (itemSelected && itemSelected.parentElement.tagName === 'LI') {
|
109
|
-
itemSelected.parentElement.focus();
|
110
|
-
focused = true;
|
111
|
-
}
|
112
|
-
}
|
113
|
-
// Si pas d'item selectionné, ou pas visible (en cas de recherche), focus sur le premier
|
114
|
-
if (selectedIdList.length === 0 || !focused) {
|
115
|
-
// On recupère tous les items
|
116
|
-
const items = overlay.getElementsByTagName('li');
|
117
|
-
let itemToFocus = items[0];
|
118
|
-
// Si select multiple, et qu'au moins un selectionné, focus sur le 2e item
|
119
|
-
if (multiple && selectedIdList.length > 0) {
|
120
|
-
itemToFocus = items[1];
|
121
|
-
}
|
122
|
-
itemToFocus.focus();
|
123
|
-
}
|
124
|
-
}, 1);
|
125
|
-
};
|
126
|
-
|
127
|
-
this.handleKeyDown = event => {
|
128
|
-
let nextItem;
|
129
|
-
if (event.key === 'ArrowDown') {
|
130
|
-
nextItem = getNextItemSelectable(document.activeElement, 'down');
|
131
|
-
} else if (event.key === 'ArrowUp') {
|
132
|
-
nextItem = getNextItemSelectable(document.activeElement, 'up');
|
133
|
-
} else if (event.key === 'Tab') {
|
134
|
-
document.body.style.overflow = 'auto';
|
135
|
-
this.setState({ open: false });
|
136
|
-
}
|
137
|
-
if (nextItem) {
|
138
|
-
nextItem.focus();
|
139
|
-
}
|
140
|
-
};
|
141
|
-
|
142
|
-
this.handleKeyDownSearch = event => {
|
143
|
-
if (this.overlay && (event.key === 'ArrowDown' || event.key === 'ArrowUp')) {
|
144
|
-
this.focusOnSelectedItem();
|
145
|
-
}
|
146
|
-
};
|
147
|
-
|
148
|
-
this.handleFocus = () => {
|
149
|
-
this.setState({ focused: true });
|
150
|
-
};
|
151
|
-
|
152
|
-
this.handleBlur = () => {
|
153
|
-
this.setState({ focused: false });
|
154
|
-
};
|
155
|
-
|
156
|
-
this.handleClose = () => {
|
157
|
-
document.body.style.overflow = 'auto';
|
158
|
-
this.setState({
|
159
|
-
open: false
|
160
|
-
});
|
161
|
-
|
162
|
-
if (this.props.onClose) {
|
163
|
-
this.props.onClose();
|
164
|
-
}
|
165
|
-
};
|
166
|
-
|
167
|
-
this.handleSelect = (event, item) => {
|
168
|
-
const { multiple, value, name, onChange, options, hierarchic } = this.props;
|
169
|
-
const { hierarchySelected, hierarchy, nbOptions } = this.state;
|
170
|
-
const hiSelected = _extends({}, hierarchySelected);
|
171
|
-
|
172
|
-
if (multiple) {
|
173
|
-
let valueList = value;
|
174
|
-
if (item.id === '_all') {
|
175
|
-
if (valueList.length === nbOptions) {
|
176
|
-
valueList = [];
|
177
|
-
if (hierarchic) {
|
178
|
-
// if hierarchic select => empty associative array of selected children
|
179
|
-
_Object$keys(hiSelected).forEach(key => {
|
180
|
-
hiSelected[key] = [];
|
181
|
-
});
|
182
|
-
}
|
183
|
-
} else {
|
184
|
-
options.forEach(option => {
|
185
|
-
if (option.hasChildren !== true && !valueList.includes(option.id) && option.id !== '_all') {
|
186
|
-
valueList.push(option.id);
|
187
|
-
} else if (option.hasChildren === true) {
|
188
|
-
// if hierarchic select => fill associative array of selected children
|
189
|
-
hiSelected[option.id] = hierarchy[option.id];
|
190
|
-
}
|
191
|
-
});
|
192
|
-
}
|
193
|
-
} else if (valueList.includes(item.id) || item.hasChildren === true && hierarchySelected[item.id].length === hierarchy[item.id].length) {
|
194
|
-
// item déjà sélectionné => on le déselectionne
|
195
|
-
if (item.hasChildren !== true) {
|
196
|
-
valueList = valueList.filter(val => {
|
197
|
-
return val !== item.id;
|
198
|
-
});
|
199
|
-
}
|
200
|
-
|
201
|
-
if (item.hasChildren === true) {
|
202
|
-
// remove all children
|
203
|
-
valueList = valueList.filter(val => {
|
204
|
-
return !this.state.hierarchy[item.id].includes(val);
|
205
|
-
});
|
206
|
-
hiSelected[item.id] = [];
|
207
|
-
} else if (item.hasOwnProperty('parentId')) {
|
208
|
-
// Si item est un enfant on l'enlève du tableau associatif des
|
209
|
-
// elmts sélectionnés
|
210
|
-
hiSelected[item.parentId].splice(hiSelected[item.parentId].indexOf(item.id), 1);
|
211
|
-
}
|
212
|
-
} else {
|
213
|
-
// item non sélectionné => on le sélectionne
|
214
|
-
if (item.hasChildren !== true) valueList.push(item.id);
|
215
|
-
|
216
|
-
if (item.hasChildren === true) {
|
217
|
-
// Si item parent => on ajoute tous les enfants
|
218
|
-
// Ou on les supprime s'ils sont déjà tous sélectionnés (dans une liste filtrée)
|
219
|
-
const idsInSuggestions = [];
|
220
|
-
this.state.suggestions.forEach(suggestion => {
|
221
|
-
if (this.state.hierarchy[item.id].includes(suggestion.id)) {
|
222
|
-
idsInSuggestions.push(suggestion.id);
|
223
|
-
}
|
224
|
-
});
|
225
|
-
// if(hierarchySelected[item.id].length > 0) {}
|
226
|
-
let allChildrenSuggestionsSelected = true;
|
227
|
-
idsInSuggestions.forEach(id => {
|
228
|
-
if (!hierarchySelected[item.id].includes(id)) {
|
229
|
-
allChildrenSuggestionsSelected = false;
|
230
|
-
}
|
231
|
-
});
|
232
|
-
|
233
|
-
if (allChildrenSuggestionsSelected === true) {
|
234
|
-
// On supprime les enfants car déjà tous sélectionnés
|
235
|
-
idsInSuggestions.forEach(id => {
|
236
|
-
valueList.splice(valueList.indexOf(id), 1);
|
237
|
-
hiSelected[item.id].splice(hiSelected[item.id].indexOf(id), 1);
|
238
|
-
});
|
239
|
-
} else {
|
240
|
-
// On ajoute tous les enfants filtrés au éléments sélectionnés
|
241
|
-
valueList = arrayUnique(valueList.concat(idsInSuggestions));
|
242
|
-
hiSelected[item.id] = arrayUnique(hiSelected[item.id].concat(idsInSuggestions));
|
243
|
-
}
|
244
|
-
|
245
|
-
this.setState({ hierarchySelected: hiSelected });
|
246
|
-
} else if (item.hasOwnProperty('parentId')) {
|
247
|
-
// Si item est un enfant on l'ajoute du tableau associatif des
|
248
|
-
// elmts sélectionnés
|
249
|
-
hiSelected[item.parentId].push(item.id);
|
250
|
-
}
|
251
|
-
}
|
252
|
-
this.setState({ hierarchySelected: hiSelected });
|
253
|
-
onChange(event, valueList);
|
254
|
-
} else {
|
255
|
-
onChange(event, item.id);
|
256
|
-
this.handleClose();
|
257
|
-
}
|
258
|
-
};
|
259
|
-
|
260
|
-
this.handleSuggestions = suggestions => {
|
261
|
-
const { options, hasAll, iconAll, translations, multiple } = this.props;
|
262
|
-
|
263
|
-
if (suggestions.length === 0) {
|
264
|
-
// Handle No Result
|
265
|
-
// FIX to remove all item
|
266
|
-
suggestions = [];
|
267
|
-
suggestions.push({
|
268
|
-
id: '_no_result',
|
269
|
-
type: 'text',
|
270
|
-
disabled: true,
|
271
|
-
centered: true,
|
272
|
-
checkbox: false,
|
273
|
-
label: translations.no_result_match
|
274
|
-
});
|
275
|
-
} else if (hasAll && suggestions.length > 0 && suggestions.length === options.length && multiple === true) {
|
276
|
-
// Handle 'All'
|
277
|
-
if (suggestions.filter(suggestion => suggestion.id === '_all').length === 0) {
|
278
|
-
const allItem = {
|
279
|
-
id: '_all',
|
280
|
-
icon: iconAll,
|
281
|
-
label: translations.all
|
282
|
-
};
|
283
|
-
if (iconAll !== false) {
|
284
|
-
allItem.type = 'icon';
|
285
|
-
}
|
286
|
-
suggestions.unshift(allItem);
|
287
|
-
}
|
288
|
-
}
|
289
|
-
|
290
|
-
this.setState({
|
291
|
-
suggestions
|
292
|
-
});
|
293
|
-
};
|
294
|
-
|
295
|
-
this.handleRequestDelete = evt => {
|
296
|
-
evt.stopPropagation();
|
297
|
-
this.props.onChange(this.props.name, []);
|
298
|
-
};
|
72
|
+
_initialiseProps.call(this);
|
299
73
|
|
300
74
|
this.state = {
|
301
75
|
open: false,
|
@@ -307,6 +81,26 @@ class HiSelect extends React.PureComponent {
|
|
307
81
|
dynamic: false
|
308
82
|
};
|
309
83
|
|
84
|
+
// Check if value is in options
|
85
|
+
let valueInOptions = false;
|
86
|
+
const val = this.props.value;
|
87
|
+
// No options provided.
|
88
|
+
if (!this.props.options.length && !val.length) {
|
89
|
+
valueInOptions = true;
|
90
|
+
}
|
91
|
+
// Check if an option match value prop.
|
92
|
+
this.props.options.forEach(item => {
|
93
|
+
if (!val.length) {
|
94
|
+
valueInOptions = true;
|
95
|
+
}
|
96
|
+
if (!valueInOptions && val.indexOf(item.id) !== -1) {
|
97
|
+
valueInOptions = true;
|
98
|
+
}
|
99
|
+
});
|
100
|
+
if (!valueInOptions) {
|
101
|
+
throw new Error('prop value provided does not match any option.');
|
102
|
+
}
|
103
|
+
|
310
104
|
if (props.hierarchic === true && props.options.length > 1) {
|
311
105
|
// Construct two associative arrays
|
312
106
|
// hierarchy[parentId] => children
|
@@ -416,13 +210,13 @@ class HiSelect extends React.PureComponent {
|
|
416
210
|
const { open, suggestions, focused } = this.state;
|
417
211
|
|
418
212
|
let display = '';
|
419
|
-
const selectedIdList = Array.isArray(value) ? value : [value];
|
213
|
+
const selectedIdList = Array.isArray(value) ? value : value ? [value] : [];
|
420
214
|
|
421
215
|
if (this.state.dynamic && selectedIdList.length === 1) {
|
422
216
|
display = translations.one_item_selected.replace('%s', selectedIdList.length);
|
423
217
|
} else if (this.state.nbOptions !== selectedIdList.length && selectedIdList.length > 1) {
|
424
218
|
display = translations.n_items_selected.replace('%s', selectedIdList.length);
|
425
|
-
} else if (this.state.nbOptions === selectedIdList.length) {
|
219
|
+
} else if (this.state.nbOptions === selectedIdList.length && this.state.nbOptions >= 1) {
|
426
220
|
display = translations.all;
|
427
221
|
} else if (selectedIdList.length === 1) {
|
428
222
|
if (type !== 'icon') {
|
@@ -486,7 +280,10 @@ class HiSelect extends React.PureComponent {
|
|
486
280
|
onFocus: this.handleFocus,
|
487
281
|
onBlur: this.handleBlur,
|
488
282
|
onMouseEnter: this.props.onMouseEnter,
|
489
|
-
onMouseLeave: this.props.onMouseLeave
|
283
|
+
onMouseLeave: this.props.onMouseLeave,
|
284
|
+
refElement: el => {
|
285
|
+
this.selectInputElement = el;
|
286
|
+
}
|
490
287
|
})
|
491
288
|
),
|
492
289
|
open && React.createElement(
|
@@ -572,6 +369,240 @@ HiSelect.defaultProps = {
|
|
572
369
|
one_child: '%s item'
|
573
370
|
}
|
574
371
|
};
|
372
|
+
|
373
|
+
var _initialiseProps = function () {
|
374
|
+
this.handleClick = () => {
|
375
|
+
document.body.style.overflow = 'hidden';
|
376
|
+
this.setState({ open: true });
|
377
|
+
const options = this.props.options.slice();
|
378
|
+
this.handleSuggestions(options);
|
379
|
+
|
380
|
+
if (this.props.onClick) {
|
381
|
+
this.props.onClick();
|
382
|
+
}
|
383
|
+
|
384
|
+
// Gestion du focus
|
385
|
+
if (this.searchField) {
|
386
|
+
// si searchable, focus sur le champs de recherche
|
387
|
+
const searchField = this.searchField;
|
388
|
+
setTimeout(() => {
|
389
|
+
searchField.focus();
|
390
|
+
}, 1);
|
391
|
+
} else if (this.overlay) {
|
392
|
+
// sinon focus sur le dernier élément selectionné
|
393
|
+
this.focusOnSelectedItem();
|
394
|
+
}
|
395
|
+
};
|
396
|
+
|
397
|
+
this.focusOnSelectedItem = () => {
|
398
|
+
// On récupère la div parent "overlay"
|
399
|
+
const overlay = findDOMNode(this.overlay);
|
400
|
+
const multiple = this.props.multiple;
|
401
|
+
const value = this.props.value;
|
402
|
+
const selectedIdList = Array.isArray(value) ? value : [value];
|
403
|
+
setTimeout(() => {
|
404
|
+
let focused = false;
|
405
|
+
// Si un ou plusieurs items sont selectionnés, on focus sur le dernier
|
406
|
+
if (selectedIdList.length > 0) {
|
407
|
+
const itemSelected = overlay.querySelector(`[data-id="${selectedIdList[selectedIdList.length - 1]}"]`);
|
408
|
+
if (itemSelected && itemSelected.parentElement.tagName === 'LI') {
|
409
|
+
itemSelected.parentElement.focus();
|
410
|
+
focused = true;
|
411
|
+
}
|
412
|
+
}
|
413
|
+
// Si pas d'item selectionné, ou pas visible (en cas de recherche), focus sur le premier
|
414
|
+
if (selectedIdList.length === 0 || !focused) {
|
415
|
+
// On recupère tous les items
|
416
|
+
const items = overlay.getElementsByTagName('li');
|
417
|
+
let itemToFocus = items[0];
|
418
|
+
// Si select multiple, et qu'au moins un selectionné, focus sur le 2e item
|
419
|
+
if (multiple && selectedIdList.length > 0) {
|
420
|
+
itemToFocus = items[1];
|
421
|
+
}
|
422
|
+
if (itemToFocus) {
|
423
|
+
itemToFocus.focus();
|
424
|
+
}
|
425
|
+
}
|
426
|
+
}, 1);
|
427
|
+
};
|
428
|
+
|
429
|
+
this.handleKeyDown = event => {
|
430
|
+
let nextItem;
|
431
|
+
if (event.key === 'ArrowDown') {
|
432
|
+
nextItem = getNextItemSelectable(document.activeElement, 'down');
|
433
|
+
} else if (event.key === 'ArrowUp') {
|
434
|
+
nextItem = getNextItemSelectable(document.activeElement, 'up');
|
435
|
+
} else if (event.key === 'Tab') {
|
436
|
+
document.body.style.overflow = 'auto';
|
437
|
+
this.setState({ open: false });
|
438
|
+
}
|
439
|
+
if (nextItem) {
|
440
|
+
nextItem.focus();
|
441
|
+
}
|
442
|
+
};
|
443
|
+
|
444
|
+
this.handleKeyDownSearch = event => {
|
445
|
+
if (this.overlay && (event.key === 'ArrowDown' || event.key === 'ArrowUp')) {
|
446
|
+
this.focusOnSelectedItem();
|
447
|
+
}
|
448
|
+
};
|
449
|
+
|
450
|
+
this.handleFocus = () => {
|
451
|
+
this.setState({ focused: true });
|
452
|
+
};
|
453
|
+
|
454
|
+
this.handleBlur = () => {
|
455
|
+
this.setState({ focused: false });
|
456
|
+
};
|
457
|
+
|
458
|
+
this.handleClose = () => {
|
459
|
+
document.body.style.overflow = 'auto';
|
460
|
+
this.setState({
|
461
|
+
open: false
|
462
|
+
});
|
463
|
+
|
464
|
+
if (this.props.onClose) {
|
465
|
+
this.props.onClose();
|
466
|
+
}
|
467
|
+
if (this.selectInputElement) {
|
468
|
+
this.selectInputElement.focus();
|
469
|
+
}
|
470
|
+
};
|
471
|
+
|
472
|
+
this.handleSelect = (event, item) => {
|
473
|
+
const { multiple, value, name, onChange, options, hierarchic } = this.props;
|
474
|
+
const { hierarchySelected, hierarchy, nbOptions } = this.state;
|
475
|
+
const hiSelected = _extends({}, hierarchySelected);
|
476
|
+
|
477
|
+
if (multiple) {
|
478
|
+
let valueList = value;
|
479
|
+
if (item.id === '_all') {
|
480
|
+
if (valueList.length === nbOptions) {
|
481
|
+
valueList = [];
|
482
|
+
if (hierarchic) {
|
483
|
+
// if hierarchic select => empty associative array of selected children
|
484
|
+
_Object$keys(hiSelected).forEach(key => {
|
485
|
+
hiSelected[key] = [];
|
486
|
+
});
|
487
|
+
}
|
488
|
+
} else {
|
489
|
+
options.forEach(option => {
|
490
|
+
if (option.hasChildren !== true && !valueList.includes(option.id) && option.id !== '_all') {
|
491
|
+
valueList.push(option.id);
|
492
|
+
} else if (option.hasChildren === true) {
|
493
|
+
// if hierarchic select => fill associative array of selected children
|
494
|
+
hiSelected[option.id] = hierarchy[option.id];
|
495
|
+
}
|
496
|
+
});
|
497
|
+
}
|
498
|
+
} else if (valueList.includes(item.id) || item.hasChildren === true && hierarchySelected[item.id].length === hierarchy[item.id].length) {
|
499
|
+
// item déjà sélectionné => on le déselectionne
|
500
|
+
if (item.hasChildren !== true) {
|
501
|
+
valueList = valueList.filter(val => {
|
502
|
+
return val !== item.id;
|
503
|
+
});
|
504
|
+
}
|
505
|
+
|
506
|
+
if (item.hasChildren === true) {
|
507
|
+
// remove all children
|
508
|
+
valueList = valueList.filter(val => {
|
509
|
+
return !this.state.hierarchy[item.id].includes(val);
|
510
|
+
});
|
511
|
+
hiSelected[item.id] = [];
|
512
|
+
} else if (item.hasOwnProperty('parentId')) {
|
513
|
+
// Si item est un enfant on l'enlève du tableau associatif des
|
514
|
+
// elmts sélectionnés
|
515
|
+
hiSelected[item.parentId].splice(hiSelected[item.parentId].indexOf(item.id), 1);
|
516
|
+
}
|
517
|
+
} else {
|
518
|
+
// item non sélectionné => on le sélectionne
|
519
|
+
if (item.hasChildren !== true) valueList.push(item.id);
|
520
|
+
|
521
|
+
if (item.hasChildren === true) {
|
522
|
+
// Si item parent => on ajoute tous les enfants
|
523
|
+
// Ou on les supprime s'ils sont déjà tous sélectionnés (dans une liste filtrée)
|
524
|
+
const idsInSuggestions = [];
|
525
|
+
this.state.suggestions.forEach(suggestion => {
|
526
|
+
if (this.state.hierarchy[item.id].includes(suggestion.id)) {
|
527
|
+
idsInSuggestions.push(suggestion.id);
|
528
|
+
}
|
529
|
+
});
|
530
|
+
// if(hierarchySelected[item.id].length > 0) {}
|
531
|
+
let allChildrenSuggestionsSelected = true;
|
532
|
+
idsInSuggestions.forEach(id => {
|
533
|
+
if (!hierarchySelected[item.id].includes(id)) {
|
534
|
+
allChildrenSuggestionsSelected = false;
|
535
|
+
}
|
536
|
+
});
|
537
|
+
|
538
|
+
if (allChildrenSuggestionsSelected === true) {
|
539
|
+
// On supprime les enfants car déjà tous sélectionnés
|
540
|
+
idsInSuggestions.forEach(id => {
|
541
|
+
valueList.splice(valueList.indexOf(id), 1);
|
542
|
+
hiSelected[item.id].splice(hiSelected[item.id].indexOf(id), 1);
|
543
|
+
});
|
544
|
+
} else {
|
545
|
+
// On ajoute tous les enfants filtrés au éléments sélectionnés
|
546
|
+
valueList = arrayUnique(valueList.concat(idsInSuggestions));
|
547
|
+
hiSelected[item.id] = arrayUnique(hiSelected[item.id].concat(idsInSuggestions));
|
548
|
+
}
|
549
|
+
|
550
|
+
this.setState({ hierarchySelected: hiSelected });
|
551
|
+
} else if (item.hasOwnProperty('parentId')) {
|
552
|
+
// Si item est un enfant on l'ajoute du tableau associatif des
|
553
|
+
// elmts sélectionnés
|
554
|
+
hiSelected[item.parentId].push(item.id);
|
555
|
+
}
|
556
|
+
}
|
557
|
+
this.setState({ hierarchySelected: hiSelected });
|
558
|
+
onChange(event, valueList);
|
559
|
+
} else {
|
560
|
+
onChange(event, item.id);
|
561
|
+
this.handleClose();
|
562
|
+
}
|
563
|
+
};
|
564
|
+
|
565
|
+
this.handleSuggestions = suggestions => {
|
566
|
+
const { options, hasAll, iconAll, translations, multiple } = this.props;
|
567
|
+
|
568
|
+
if (suggestions.length === 0) {
|
569
|
+
// Handle No Result
|
570
|
+
// FIX to remove all item
|
571
|
+
suggestions = [];
|
572
|
+
suggestions.push({
|
573
|
+
id: '_no_result',
|
574
|
+
type: 'text',
|
575
|
+
disabled: true,
|
576
|
+
centered: true,
|
577
|
+
checkbox: false,
|
578
|
+
label: translations.no_result_match
|
579
|
+
});
|
580
|
+
} else if (hasAll && suggestions.length > 0 && suggestions.length === options.length && multiple === true) {
|
581
|
+
// Handle 'All'
|
582
|
+
if (suggestions.filter(suggestion => suggestion.id === '_all').length === 0) {
|
583
|
+
const allItem = {
|
584
|
+
id: '_all',
|
585
|
+
icon: iconAll,
|
586
|
+
label: translations.all
|
587
|
+
};
|
588
|
+
if (iconAll !== false) {
|
589
|
+
allItem.type = 'icon';
|
590
|
+
}
|
591
|
+
suggestions.unshift(allItem);
|
592
|
+
}
|
593
|
+
}
|
594
|
+
|
595
|
+
this.setState({
|
596
|
+
suggestions
|
597
|
+
});
|
598
|
+
};
|
599
|
+
|
600
|
+
this.handleRequestDelete = evt => {
|
601
|
+
evt.stopPropagation();
|
602
|
+
this.props.onChange(this.props.name, []);
|
603
|
+
};
|
604
|
+
};
|
605
|
+
|
575
606
|
HiSelect.propTypes = process.env.NODE_ENV !== "production" ? {
|
576
607
|
/**
|
577
608
|
* Affiche une checkbox pour chaque éléments, par défaut si options est nested
|
@@ -652,6 +683,7 @@ HiSelect.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
652
683
|
* Fonction de callback appelée lorsqu'on écrit dans la barre de recherche
|
653
684
|
* A utiliser pour les selects avec des données dynamiques
|
654
685
|
*
|
686
|
+
* @param {object} event
|
655
687
|
* @param {string} value
|
656
688
|
*/
|
657
689
|
onSearch: PropTypes.func,
|
@@ -31,9 +31,10 @@ class HiSelectField extends React.PureComponent {
|
|
31
31
|
iconAll,
|
32
32
|
checkbox,
|
33
33
|
searchable,
|
34
|
-
translations
|
34
|
+
translations,
|
35
|
+
className
|
35
36
|
} = _props,
|
36
|
-
others = _objectWithoutProperties(_props, ['label', 'required', 'disabled', 'error', 'errorText', 'helperText', 'helperIcon', 'id', 'name', 'value', 'options', 'type', 'multiple', 'iconAll', 'checkbox', 'searchable', 'translations']);
|
37
|
+
others = _objectWithoutProperties(_props, ['label', 'required', 'disabled', 'error', 'errorText', 'helperText', 'helperIcon', 'id', 'name', 'value', 'options', 'type', 'multiple', 'iconAll', 'checkbox', 'searchable', 'translations', 'className']);
|
37
38
|
|
38
39
|
return React.createElement(
|
39
40
|
HiFormControl,
|
@@ -45,7 +46,8 @@ class HiSelectField extends React.PureComponent {
|
|
45
46
|
error: error,
|
46
47
|
errorText: errorText,
|
47
48
|
helperText: helperText,
|
48
|
-
helperIcon: helperIcon
|
49
|
+
helperIcon: helperIcon,
|
50
|
+
className: className
|
49
51
|
},
|
50
52
|
React.createElement(HiSelect, _extends({
|
51
53
|
id: id,
|
@@ -58,10 +60,6 @@ class HiSelectField extends React.PureComponent {
|
|
58
60
|
checkbox: checkbox,
|
59
61
|
searchable: searchable,
|
60
62
|
translations: translations,
|
61
|
-
onClick: this.handleClick,
|
62
|
-
onMouseEnter: this.handleMouseEnter,
|
63
|
-
onMouseLeave: this.handleMouseLeave,
|
64
|
-
onClose: this.handleClose,
|
65
63
|
disabled: disabled,
|
66
64
|
error: error
|
67
65
|
}, others))
|
@@ -70,6 +68,10 @@ class HiSelectField extends React.PureComponent {
|
|
70
68
|
}
|
71
69
|
|
72
70
|
HiSelectField.propTypes = process.env.NODE_ENV !== "production" ? {
|
71
|
+
/**
|
72
|
+
* Surcharge des styles
|
73
|
+
*/
|
74
|
+
className: PropTypes.string,
|
73
75
|
/**
|
74
76
|
* Si `true`, l'input sera inactif.
|
75
77
|
*/
|