haya-select 1.0.22 → 1.0.24
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/package.json +2 -2
- package/src/select/index.jsx +20 -6
- package/src/select/option-group.jsx +12 -12
- package/src/select/option.jsx +27 -29
- package/src/select/style.scss +9 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "haya-select",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.24",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"debounce": "^1.2.1",
|
|
14
14
|
"diggerize": "^1.0.4",
|
|
15
15
|
"fetching-object": "^1.0.1",
|
|
16
|
-
"set-state-compare": "^1.0.
|
|
16
|
+
"set-state-compare": "^1.0.27"
|
|
17
17
|
},
|
|
18
18
|
"peerDependencies": {
|
|
19
19
|
"prop-types": ">= 15.7.2",
|
package/src/select/index.jsx
CHANGED
|
@@ -240,6 +240,14 @@ export default class HayaSelect extends React.PureComponent {
|
|
|
240
240
|
}
|
|
241
241
|
}
|
|
242
242
|
|
|
243
|
+
isActive() {
|
|
244
|
+
if (this.t.endOfSelectRef.current) {
|
|
245
|
+
return true
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
return false
|
|
249
|
+
}
|
|
250
|
+
|
|
243
251
|
async loadDefaultValuesFromOptionsCallback() {
|
|
244
252
|
const defaultValues = this.defaultValues()
|
|
245
253
|
|
|
@@ -329,6 +337,8 @@ export default class HayaSelect extends React.PureComponent {
|
|
|
329
337
|
focusTextInput = () => digg(this.t.searchTextInputRef, "current").focus()
|
|
330
338
|
|
|
331
339
|
setOptionsPosition() {
|
|
340
|
+
if (!this.isActive()) return // Debounce after un-mount handeling.
|
|
341
|
+
|
|
332
342
|
this.setOptionsPositionBelow()
|
|
333
343
|
this.setOptionsPositionAboveIfOutsideScreen()
|
|
334
344
|
}
|
|
@@ -348,7 +358,7 @@ export default class HayaSelect extends React.PureComponent {
|
|
|
348
358
|
}
|
|
349
359
|
|
|
350
360
|
setOptionsPositionAbove() {
|
|
351
|
-
const {optionsContainerRef, currentSelectedRef} = this.t
|
|
361
|
+
const {optionsContainerRef, currentSelectedRef, searchTextInputRef} = this.t
|
|
352
362
|
const optionsHeight = digg(optionsContainerRef, "current", "offsetHeight")
|
|
353
363
|
const position = currentSelectedRef.current.getBoundingClientRect()
|
|
354
364
|
const {left, top, width} = digs(position, "left", "top", "width")
|
|
@@ -365,7 +375,7 @@ export default class HayaSelect extends React.PureComponent {
|
|
|
365
375
|
scrollLeft: document.documentElement.scrollLeft,
|
|
366
376
|
scrollTop: document.documentElement.scrollTop
|
|
367
377
|
},
|
|
368
|
-
() =>
|
|
378
|
+
() => searchTextInputRef.current.focus()
|
|
369
379
|
)
|
|
370
380
|
}
|
|
371
381
|
|
|
@@ -385,7 +395,7 @@ export default class HayaSelect extends React.PureComponent {
|
|
|
385
395
|
scrollLeft: document.documentElement.scrollLeft,
|
|
386
396
|
scrollTop: document.documentElement.scrollTop
|
|
387
397
|
},
|
|
388
|
-
() =>
|
|
398
|
+
() => searchTextInputRef.current.focus()
|
|
389
399
|
)
|
|
390
400
|
}
|
|
391
401
|
|
|
@@ -447,9 +457,9 @@ export default class HayaSelect extends React.PureComponent {
|
|
|
447
457
|
)
|
|
448
458
|
}
|
|
449
459
|
|
|
450
|
-
onOptionClicked = (
|
|
451
|
-
|
|
452
|
-
|
|
460
|
+
onOptionClicked = (event, loadedOption) => {
|
|
461
|
+
event.preventDefault()
|
|
462
|
+
event.stopPropagation()
|
|
453
463
|
|
|
454
464
|
const {onChange, toggleOptions} = this.props
|
|
455
465
|
const {multiple} = this.p
|
|
@@ -475,6 +485,9 @@ export default class HayaSelect extends React.PureComponent {
|
|
|
475
485
|
newState.currentOptions = currentOptions.filter((currentOption) => currentOption.value != loadedOption.value)
|
|
476
486
|
}
|
|
477
487
|
} else {
|
|
488
|
+
// Don't do anything if the clicked option is disabled
|
|
489
|
+
if (loadedOption.disabled) return
|
|
490
|
+
|
|
478
491
|
if (toggleOptions) {
|
|
479
492
|
newToggled[loadedOption.value] = 0
|
|
480
493
|
newState.toggled = newToggled
|
|
@@ -500,6 +513,7 @@ export default class HayaSelect extends React.PureComponent {
|
|
|
500
513
|
}
|
|
501
514
|
|
|
502
515
|
onChange({
|
|
516
|
+
event,
|
|
503
517
|
options: this.shape.currentOptions,
|
|
504
518
|
toggles
|
|
505
519
|
})
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import PropTypes from "prop-types"
|
|
2
|
-
import
|
|
2
|
+
import {memo} from "react"
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
option
|
|
7
|
-
|
|
4
|
+
const OptionGroup = ({option}) => {
|
|
5
|
+
return (
|
|
6
|
+
<div className="haya-select--option-group">
|
|
7
|
+
{option.text}
|
|
8
|
+
</div>
|
|
9
|
+
)
|
|
10
|
+
}
|
|
8
11
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
<div className="haya-select--option-group">
|
|
12
|
-
{this.props.option.text}
|
|
13
|
-
</div>
|
|
14
|
-
)
|
|
15
|
-
}
|
|
12
|
+
OptionGroup.propTypes = {
|
|
13
|
+
option: PropTypes.object.isRequired
|
|
16
14
|
}
|
|
15
|
+
|
|
16
|
+
export default memo(OptionGroup)
|
package/src/select/option.jsx
CHANGED
|
@@ -1,34 +1,32 @@
|
|
|
1
|
-
import {digs} from "diggerize"
|
|
2
1
|
import PropTypes from "prop-types"
|
|
3
|
-
import
|
|
2
|
+
import {memo, useMemo} from "react"
|
|
3
|
+
import useShape from "set-state-compare/src/use-shape.js"
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
onOptionClicked: PropTypes.func.isRequired,
|
|
10
|
-
option: PropTypes.object.isRequired,
|
|
11
|
-
presentOption: PropTypes.func.isRequired
|
|
12
|
-
}
|
|
5
|
+
const Option = (props) => {
|
|
6
|
+
const s = useShape(props)
|
|
7
|
+
const onClick = useCallback((e) => s.p.onOptionClicked(e, s.p.option), [])
|
|
8
|
+
const selected = Boolean(s.p.currentOptions.find((currentOption) => currentOption.value == s.p.option.value))
|
|
13
9
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
style={this.style}
|
|
27
|
-
>
|
|
28
|
-
{this.props.presentOption(option)}
|
|
29
|
-
</div>
|
|
30
|
-
)
|
|
31
|
-
}
|
|
10
|
+
return (
|
|
11
|
+
<div
|
|
12
|
+
className="haya-select-option"
|
|
13
|
+
data-disabled={Boolean(s.p.option.disabled)}
|
|
14
|
+
data-selected={selected}
|
|
15
|
+
data-value={s.p.option.value}
|
|
16
|
+
onClick={onClick}
|
|
17
|
+
>
|
|
18
|
+
{props.presentOption(s.p.option)}
|
|
19
|
+
</div>
|
|
20
|
+
)
|
|
21
|
+
}
|
|
32
22
|
|
|
33
|
-
|
|
23
|
+
Option.propTypes = {
|
|
24
|
+
currentOptions: PropTypes.array.isRequired,
|
|
25
|
+
disabled: PropTypes.bool,
|
|
26
|
+
icon: PropTypes.string,
|
|
27
|
+
onOptionClicked: PropTypes.func.isRequired,
|
|
28
|
+
option: PropTypes.object.isRequired,
|
|
29
|
+
presentOption: PropTypes.func.isRequired
|
|
34
30
|
}
|
|
31
|
+
|
|
32
|
+
export default memo(Option)
|
package/src/select/style.scss
CHANGED