@dvrd/dvr-controls 1.0.73 → 1.0.75

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": "@dvrd/dvr-controls",
3
- "version": "1.0.73",
3
+ "version": "1.0.75",
4
4
  "description": "Custom web controls",
5
5
  "main": "index.ts",
6
6
  "files": [
@@ -3,7 +3,7 @@
3
3
  */
4
4
  import './style/dvrdSelect.scss';
5
5
 
6
- import React, {MouseEventHandler, ReactElement, useEffect, useMemo, useRef, useState} from 'react';
6
+ import React, {ReactElement, useEffect, useMemo, useRef, useState} from 'react';
7
7
  import classNames from 'classnames';
8
8
  import {ChangeFunction, ErrorType, SelectItemShape} from '../util/interfaces';
9
9
  import {hasHover, stopPropagation} from '../util/controlUtil';
@@ -11,7 +11,7 @@ import AwesomeIcon from '../icon/awesomeIcon';
11
11
  import delay from 'lodash.delay';
12
12
 
13
13
  interface Props {
14
- onChange: (selected: Array<string | number>, submit: boolean) => MouseEventHandler;
14
+ onChange: (selected: Array<string | number>, submit: boolean) => VoidFunction;
15
15
  onChangeSearch: ChangeFunction;
16
16
  selected: Array<string | number>;
17
17
  items: SelectItemShape[];
@@ -72,8 +72,8 @@ export default function DvrdMultiSelect(props: Props) {
72
72
  return function (evt: React.MouseEvent) {
73
73
  stopPropagation(evt);
74
74
  if (selected.includes(_value))
75
- onChange(selected.filter((value: string | number) => value !== _value), !submitOnClose)(evt);
76
- else onChange(selected.concat(_value), !submitOnClose)(evt);
75
+ onChange(selected.filter((value: string | number) => value !== _value), !submitOnClose)();
76
+ else onChange(selected.concat(_value), !submitOnClose)();
77
77
  }
78
78
  }
79
79
 
@@ -200,7 +200,7 @@ export default function DvrdMultiSelect(props: Props) {
200
200
  if (open) addClickListener();
201
201
  else {
202
202
  removeClickListener();
203
- if (submitOnClose && !isFirstRender) onChange(selected, true);
203
+ if (submitOnClose && !isFirstRender) onChange(selected, true)();
204
204
  }
205
205
  return function () {
206
206
  removeClickListener();
@@ -45,8 +45,6 @@ export default function DvrdSelectController(props: Props) {
45
45
  if (!search) return items;
46
46
  return items.filter((item) => stringContains(item.label.toString(), search));
47
47
  }, [items, search]);
48
- const _value = useMemo(() => unControlled ? internalValue : value,
49
- [unControlled, internalValue, value]);
50
48
 
51
49
  function _onChange(value: ValueType, submit: boolean = true) {
52
50
  return function () {
@@ -62,15 +60,18 @@ export default function DvrdSelectController(props: Props) {
62
60
  useEffect(() => {
63
61
  if (multi && !Array.isArray(value)) throw new TypeError('Value must be an array in multi mode');
64
62
  else if (!multi && Array.isArray(value)) throw new TypeError('Value must be a string or number in single mode');
63
+ }, [value, multi]);
64
+
65
+ useEffect(() => {
65
66
  if (!unControlled && value !== internalValue) setInternalValue(value);
66
- }, [value, multi, unControlled]);
67
+ }, [value, unControlled]);
67
68
 
68
69
  const itemsPosition = props.itemsPosition ?? 'bottom';
69
70
  const optionsContainerHeight = props.optionsContainerHeight ?? '15rem';
70
71
  const selectOnly = props.selectOnly !== false;
71
72
  if (multi) return (
72
73
  <DvrdMultiSelect onChange={_onChange} onChangeSearch={onChangeSearch}
73
- selected={_value as Array<string | number>} items={_items} itemsPosition={itemsPosition}
74
+ selected={internalValue as Array<string | number>} items={_items} itemsPosition={itemsPosition}
74
75
  selectOnly={selectOnly} searchValue={search} optionsContainerHeight={optionsContainerHeight}
75
76
  className={className} error={error} label={label} arrowClassName={arrowClassName}
76
77
  errorClassName={errorClassName} itemClassName={itemClassName} submitOnClose={submitOnClose}
@@ -78,7 +79,7 @@ export default function DvrdSelectController(props: Props) {
78
79
  labelClassName={labelClassName} disabled={disabled} placeholder={placeholder}/>
79
80
  );
80
81
  return (
81
- <DvrdSelect onChange={_onChange} onChangeSearch={onChangeSearch} value={_value as number | string}
82
+ <DvrdSelect onChange={_onChange} onChangeSearch={onChangeSearch} value={internalValue as number | string}
82
83
  items={_items} itemsPosition={itemsPosition} selectOnly={selectOnly} searchValue={search}
83
84
  optionsContainerHeight={optionsContainerHeight} className={className} error={error} label={label}
84
85
  arrowClassName={arrowClassName} errorClassName={errorClassName} itemClassName={itemClassName}