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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "haya-select",
3
- "version": "1.0.22",
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.19"
16
+ "set-state-compare": "^1.0.27"
17
17
  },
18
18
  "peerDependencies": {
19
19
  "prop-types": ">= 15.7.2",
@@ -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
- () => digg(this.t.searchTextInputRef, "current").focus()
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
- () => digg(searchTextInputRef, "current").focus()
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 = (e, loadedOption) => {
451
- e.preventDefault()
452
- e.stopPropagation()
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 React from "react"
2
+ import {memo} from "react"
3
3
 
4
- export default class OptionGroup extends React.PureComponent {
5
- static propTypes = {
6
- option: PropTypes.object.isRequired
7
- }
4
+ const OptionGroup = ({option}) => {
5
+ return (
6
+ <div className="haya-select--option-group">
7
+ {option.text}
8
+ </div>
9
+ )
10
+ }
8
11
 
9
- render() {
10
- return (
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)
@@ -1,34 +1,32 @@
1
- import {digs} from "diggerize"
2
1
  import PropTypes from "prop-types"
3
- import React from "react"
2
+ import {memo, useMemo} from "react"
3
+ import useShape from "set-state-compare/src/use-shape.js"
4
4
 
5
- export default class Option extends React.PureComponent {
6
- static propTypes = {
7
- currentOptions: PropTypes.array.isRequired,
8
- icon: PropTypes.string,
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
- style = {cursor: "pointer"}
15
-
16
- render() {
17
- const {currentOptions, option} = digs(this.props, "currentOptions", "option")
18
- const selected = Boolean(currentOptions.find((currentOption) => currentOption.value == option.value))
19
-
20
- return (
21
- <div
22
- className="haya-select-option"
23
- data-selected={selected}
24
- data-value={option.value}
25
- onClick={this.onClick}
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
- onClick = (e) => this.props.onOptionClicked(e, this.props.option)
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)
@@ -46,6 +46,15 @@
46
46
  padding: 4px 8px;
47
47
  color: #000;
48
48
 
49
+ &[data-disabled="true"] {
50
+ cursor: default;
51
+ opacity: .6;
52
+ }
53
+
54
+ &[data-disabled="false"] {
55
+ cursor: pointer;
56
+ }
57
+
49
58
  &[data-selected="true"] {
50
59
  background-color: #80b2ff;
51
60
  }