@kwiz/fluentui 1.0.128 → 1.0.129
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.
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { DropdownProps } from '@fluentui/react-components';
|
|
2
2
|
import React from 'react';
|
|
3
|
-
type ForwardProps = Omit<DropdownProps, "onSelect" | "selectedOptions" | "clearable">;
|
|
4
|
-
interface
|
|
3
|
+
type ForwardProps = Omit<DropdownProps, "onSelect" | "selectedOptions" | "clearable" | "defaultSelectedOptions">;
|
|
4
|
+
interface iProps<keyType, dataType> extends ForwardProps {
|
|
5
5
|
required?: boolean;
|
|
6
|
-
selected: keyType | keyType[];
|
|
7
6
|
items: {
|
|
8
7
|
key: keyType;
|
|
9
8
|
value: string;
|
|
@@ -25,7 +24,14 @@ interface IProps<keyType, dataType> extends ForwardProps {
|
|
|
25
24
|
data?: dataType;
|
|
26
25
|
}[]) => void;
|
|
27
26
|
}
|
|
28
|
-
|
|
27
|
+
type tProps<keyType, dataType> = iProps<keyType, dataType> & ({
|
|
28
|
+
selected: keyType | keyType[];
|
|
29
|
+
defaultSelected?: never;
|
|
30
|
+
} | {
|
|
31
|
+
selected?: never;
|
|
32
|
+
defaultSelected: keyType | keyType[];
|
|
33
|
+
});
|
|
34
|
+
export declare const DropdownEX: <keyType extends string = string, dataType = never>(props: tProps<keyType, dataType> & React.RefAttributes<HTMLButtonElement>) => React.JSX.Element | null;
|
|
29
35
|
/** @deprecated use normal DropdownEX it is now generic */
|
|
30
|
-
export declare function getDropdownEX<keyType extends string = string, dataType = never>(): (props:
|
|
36
|
+
export declare function getDropdownEX<keyType extends string = string, dataType = never>(): (props: tProps<keyType, dataType> & React.RefAttributes<HTMLButtonElement>) => React.JSX.Element | null;
|
|
31
37
|
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { Dropdown, makeStyles, mergeClasses, Option } from '@fluentui/react-components';
|
|
3
|
-
import { CommonLogger, filterEmptyEntries, firstOrNull, isNotEmptyArray, isNotEmptyString, isNullOrUndefined } from '@kwiz/common';
|
|
4
|
-
import React, { useMemo, useState } from 'react';
|
|
3
|
+
import { CommonLogger, filterEmptyEntries, firstOrNull, isNotEmptyArray, isNotEmptyString, isNullOrUndefined, isUndefined } from '@kwiz/common';
|
|
4
|
+
import React, { useEffect, useMemo, useState } from 'react';
|
|
5
5
|
import { useKWIZFluentContext } from '../helpers/context-internal';
|
|
6
6
|
const logger = new CommonLogger("DropdownEX");
|
|
7
7
|
const useStyles = makeStyles({
|
|
@@ -17,11 +17,24 @@ const useStyles = makeStyles({
|
|
|
17
17
|
function $DropdownEX(props, ref) {
|
|
18
18
|
const classes = useStyles();
|
|
19
19
|
const ctx = useKWIZFluentContext();
|
|
20
|
-
const
|
|
20
|
+
const [isUnControlled, setIsUnControlled] = useState(!isUndefined(props.defaultSelected));
|
|
21
|
+
const __isUnControlled = !isUndefined(props.defaultSelected);
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
if (__isUnControlled !== isUnControlled) {
|
|
24
|
+
logger.error(`A DropdownEX control was switched from controlled to uncontrolled mode. This is not supported.`);
|
|
25
|
+
setIsUnControlled(__isUnControlled);
|
|
26
|
+
if (!__isUnControlled) {
|
|
27
|
+
setUncontrolledSelected(props.selected);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}, [__isUnControlled, isUnControlled]);
|
|
31
|
+
const [uncontrolledSelected, setUncontrolledSelected] = useState(isUnControlled ? props.defaultSelected : props.selected);
|
|
32
|
+
const selectedValueToUse = isUnControlled ? uncontrolledSelected : props.selected;
|
|
33
|
+
const selected = Array.isArray(selectedValueToUse) ? selectedValueToUse : isNullOrUndefined(selectedValueToUse) ? [] : [selectedValueToUse];
|
|
21
34
|
//sometimes control will lose value when re-rendered
|
|
22
35
|
//use case: public forms when editing other fields after the dropdown was set
|
|
23
36
|
//re-set the text value manually to fix
|
|
24
|
-
let text = filterEmptyEntries((Array.isArray(
|
|
37
|
+
let text = filterEmptyEntries((Array.isArray(selectedValueToUse) ? selectedValueToUse : [selectedValueToUse]).map(s => {
|
|
25
38
|
let v = firstOrNull(props.items, i => i.key === s);
|
|
26
39
|
return v ? v.value : '';
|
|
27
40
|
})).join(', ');
|
|
@@ -49,10 +62,13 @@ function $DropdownEX(props, ref) {
|
|
|
49
62
|
let o = firstOrNull(props.items, i => i.key === data.optionValue);
|
|
50
63
|
if (props.multiselect) {
|
|
51
64
|
let current = data.selectedOptions.map(s => firstOrNull(props.items, i => i.key === s));
|
|
65
|
+
setUncontrolledSelected(current.map(o => o.key));
|
|
52
66
|
props.onSelect(o, current);
|
|
53
67
|
}
|
|
54
|
-
else
|
|
68
|
+
else {
|
|
69
|
+
setUncontrolledSelected(o.key);
|
|
55
70
|
props.onSelect(o);
|
|
71
|
+
}
|
|
56
72
|
}, children: items.map(i => _jsx(Option, { value: i.key, text: i.value, children: i.option ? i.option : i.value }, i.key)) })));
|
|
57
73
|
}
|
|
58
74
|
export const DropdownEX = React.forwardRef($DropdownEX);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dropdown.js","sourceRoot":"","sources":["../../src/controls/dropdown.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAiB,UAAU,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACvG,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,WAAW,EAAE,eAAe,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"dropdown.js","sourceRoot":"","sources":["../../src/controls/dropdown.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAiB,UAAU,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACvG,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,WAAW,EAAE,eAAe,E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