@khanacademy/wonder-blocks-dropdown 9.0.0 → 9.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 Khan Academy
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/es/index.js CHANGED
@@ -96,10 +96,10 @@ class ActionItem extends React.Component {
96
96
  const labelComponent = typeof label === "string" ? React.createElement(LabelMedium, {
97
97
  lang: lang,
98
98
  style: styles$c.label
99
- }, label) : React.cloneElement(label, _extends({
99
+ }, label) : (React.cloneElement(label, _extends({
100
100
  lang,
101
101
  style: styles$c.label
102
- }, label.props));
102
+ }, label.props)));
103
103
  return React.createElement(CompactCell, {
104
104
  disabled: disabled,
105
105
  horizontalRule: horizontalRule,
@@ -232,7 +232,7 @@ const styles$a = StyleSheet.create({
232
232
  });
233
233
 
234
234
  const _excluded$5 = ["disabled", "label", "selected", "testId", "leftAccessory", "horizontalRule", "parentComponent", "rightAccessory", "style", "subtitle1", "subtitle2", "value", "onClick", "onToggle", "variant", "role"];
235
- const StyledListItem = addStyle("li");
235
+ const StyledLi = addStyle("li");
236
236
  class OptionItem extends React.Component {
237
237
  constructor(...args) {
238
238
  super(...args);
@@ -320,7 +320,7 @@ class OptionItem extends React.Component {
320
320
  selected
321
321
  } = this.props;
322
322
  if (parentComponent === "listbox") {
323
- return React.createElement(StyledListItem, {
323
+ return React.createElement(StyledLi, {
324
324
  onMouseDown: e => {
325
325
  e.preventDefault();
326
326
  },
@@ -340,7 +340,7 @@ OptionItem.defaultProps = {
340
340
  disabled: false,
341
341
  focused: false,
342
342
  horizontalRule: "none",
343
- onToggle: () => void 0,
343
+ onToggle: () => undefined,
344
344
  role: "option",
345
345
  selected: false
346
346
  };
@@ -455,10 +455,11 @@ class SeparatorItem extends React.Component {
455
455
  return instance && instance.type && instance.type.__IS_SEPARATOR_ITEM__;
456
456
  }
457
457
  render() {
458
- return React.createElement(View, {
459
- style: [styles$8.separator, this.props.style],
460
- "aria-hidden": "true"
461
- });
458
+ return (React.createElement(View, {
459
+ style: [styles$8.separator, this.props.style],
460
+ "aria-hidden": "true"
461
+ })
462
+ );
462
463
  }
463
464
  }
464
465
  SeparatorItem.__IS_SEPARATOR_ITEM__ = true;
@@ -610,7 +611,7 @@ class DropdownCoreVirtualized extends React.Component {
610
611
  }
611
612
  setWidth() {
612
613
  const rootNode = ReactDOM.findDOMNode(this);
613
- const parentNode = rootNode == null ? void 0 : rootNode.parentElement;
614
+ const parentNode = rootNode == null ? undefined : rootNode.parentElement;
614
615
  if (parentNode) {
615
616
  const width = parentNode.getBoundingClientRect().width;
616
617
  this.setState({
@@ -827,10 +828,10 @@ class DropdownCore extends React.Component {
827
828
  }
828
829
  constructor(props) {
829
830
  super(props);
830
- this.popperElement = void 0;
831
- this.virtualizedListRef = void 0;
832
- this.handleKeyDownDebounced = void 0;
833
- this.textSuggestion = void 0;
831
+ this.popperElement = undefined;
832
+ this.virtualizedListRef = undefined;
833
+ this.handleKeyDownDebounced = undefined;
834
+ this.textSuggestion = undefined;
834
835
  this.focusedIndex = -1;
835
836
  this.focusedOriginalIndex = -1;
836
837
  this.itemsClicked = false;
@@ -1509,7 +1510,7 @@ const _excluded$3 = ["text", "opened"];
1509
1510
  class ActionMenu extends React.Component {
1510
1511
  constructor(...args) {
1511
1512
  super(...args);
1512
- this.openerElement = void 0;
1513
+ this.openerElement = undefined;
1513
1514
  this.state = {
1514
1515
  opened: false
1515
1516
  };
@@ -1736,6 +1737,7 @@ class SelectOpener extends React.Component {
1736
1737
  "data-testid": testId,
1737
1738
  id: id,
1738
1739
  role: "combobox",
1740
+ type: "button",
1739
1741
  style: style,
1740
1742
  onClick: !disabled ? this.handleClick : undefined,
1741
1743
  onKeyDown: !disabled ? this.handleKeyDown : undefined,
@@ -2235,7 +2237,7 @@ const MultiSelect = props => {
2235
2237
  case 1:
2236
2238
  const selectedItem = children.find(option => option.props.value === selectedValues[0]);
2237
2239
  if (selectedItem) {
2238
- const selectedLabel = getSelectOpenerLabel(showOpenerLabelAsText, selectedItem == null ? void 0 : selectedItem.props);
2240
+ const selectedLabel = getSelectOpenerLabel(showOpenerLabelAsText, selectedItem == null ? undefined : selectedItem.props);
2239
2241
  if (selectedLabel) {
2240
2242
  return selectedLabel;
2241
2243
  } else {
@@ -2543,7 +2545,7 @@ function useListbox({
2543
2545
  const renderList = React.useMemo(() => {
2544
2546
  return options.map((component, index) => {
2545
2547
  const isSingleSelection = selectionType === "single" && typeof selected === "string";
2546
- const isSelected = (isSingleSelection ? selected === component.props.value : selected == null ? void 0 : selected.includes(component.props.value)) || false;
2548
+ const isSelected = (isSingleSelection ? selected === component.props.value : selected == null ? undefined : selected.includes(component.props.value)) || false;
2547
2549
  const optionId = id ? `${id}-option-${index}` : `option-${index}`;
2548
2550
  return React.cloneElement(component, {
2549
2551
  key: index,
@@ -2590,19 +2592,19 @@ function useMultipleSelection({
2590
2592
  if (key === "ArrowLeft") {
2591
2593
  setFocusedMultiSelectIndex(prev => {
2592
2594
  const newIndex = prev - 1;
2593
- return newIndex < 0 ? (selected == null ? void 0 : selected.length) - 1 : newIndex;
2595
+ return newIndex < 0 ? (selected == null ? undefined : selected.length) - 1 : newIndex;
2594
2596
  });
2595
2597
  }
2596
2598
  if (key === "ArrowRight") {
2597
2599
  setFocusedMultiSelectIndex(prev => {
2598
2600
  const newIndex = prev + 1;
2599
- return newIndex >= (selected == null ? void 0 : selected.length) ? 0 : newIndex;
2601
+ return newIndex >= (selected == null ? undefined : selected.length) ? 0 : newIndex;
2600
2602
  });
2601
2603
  }
2602
2604
  if (inputValue === "" && key === "Backspace") {
2603
2605
  let newSelected = [];
2604
2606
  if (focusedMultiSelectIndex < 0) {
2605
- newSelected = selected == null ? void 0 : selected.slice(0, -1);
2607
+ newSelected = selected == null ? undefined : selected.slice(0, -1);
2606
2608
  } else {
2607
2609
  newSelected = selected.filter((_, index) => index !== focusedMultiSelectIndex);
2608
2610
  }
@@ -2610,7 +2612,7 @@ function useMultipleSelection({
2610
2612
  setFocusedMultiSelectIndex(-1);
2611
2613
  }
2612
2614
  if (focusedMultiSelectIndex >= 0 && key === "Enter") {
2613
- const newSelected = selected == null ? void 0 : selected.filter((_, index) => index !== focusedMultiSelectIndex);
2615
+ const newSelected = selected == null ? undefined : selected.filter((_, index) => index !== focusedMultiSelectIndex);
2614
2616
  setSelected(newSelected);
2615
2617
  setFocusedMultiSelectIndex(-1);
2616
2618
  }
@@ -2651,11 +2653,11 @@ function ComboboxLiveRegion({
2651
2653
  const lastSelectedValue = React.useRef(null);
2652
2654
  const [message, setMessage] = React.useState("");
2653
2655
  React.useEffect(() => {
2654
- if (selected && selected !== (lastSelectedValue == null ? void 0 : lastSelectedValue.current)) {
2656
+ if (selected && selected !== (lastSelectedValue == null ? undefined : lastSelectedValue.current)) {
2655
2657
  var _lastSelectedValue$cu, _lastSelectedValue$cu2, _selected$length;
2656
2658
  let newMessage = "";
2657
- const lastSelectedLength = (_lastSelectedValue$cu = lastSelectedValue == null ? void 0 : (_lastSelectedValue$cu2 = lastSelectedValue.current) == null ? void 0 : _lastSelectedValue$cu2.length) != null ? _lastSelectedValue$cu : 0;
2658
- const selectedLength = (_selected$length = selected == null ? void 0 : selected.length) != null ? _selected$length : 0;
2659
+ const lastSelectedLength = (_lastSelectedValue$cu = lastSelectedValue == null || (_lastSelectedValue$cu2 = lastSelectedValue.current) == null ? undefined : _lastSelectedValue$cu2.length) != null ? _lastSelectedValue$cu : 0;
2660
+ const selectedLength = (_selected$length = selected == null ? undefined : selected.length) != null ? _selected$length : 0;
2659
2661
  if (Array.isArray(selected) && selected.length > 0) {
2660
2662
  const currentLabels = selectedLabels.join(", ");
2661
2663
  const selectedState = selectedLength > lastSelectedLength ? labels.selected(currentLabels) : labels.unselected(currentLabels);
@@ -2809,7 +2811,7 @@ function StandaloneListbox(props) {
2809
2811
  });
2810
2812
  React.useEffect(() => {
2811
2813
  if (selected && selected !== value) {
2812
- onChange == null ? void 0 : onChange(selected);
2814
+ onChange == null || onChange(selected);
2813
2815
  }
2814
2816
  }, [onChange, selected, value]);
2815
2817
  return React.createElement(View, {
@@ -2881,7 +2883,7 @@ function Combobox({
2881
2883
  testId,
2882
2884
  value = ""
2883
2885
  }) {
2884
- var _renderList$find, _renderList$focusedIn, _renderList$focusedIn2;
2886
+ var _renderList$find, _renderList$focusedIn;
2885
2887
  const generatedUniqueId = useId();
2886
2888
  const uniqueId = id != null ? id : generatedUniqueId;
2887
2889
  const comboboxRef = React.useRef(null);
@@ -2912,7 +2914,7 @@ function Combobox({
2912
2914
  disableSpaceSelection: true,
2913
2915
  selectionType
2914
2916
  });
2915
- const itemFromSelected = (_renderList$find = renderList.find(item => item.props.value === selected)) == null ? void 0 : _renderList$find.props;
2917
+ const itemFromSelected = (_renderList$find = renderList.find(item => item.props.value === selected)) == null ? undefined : _renderList$find.props;
2916
2918
  const labelFromSelected = itemFromSelected ? getLabel(itemFromSelected) : "";
2917
2919
  const initialValue = typeof value === "string" ? labelFromSelected : "";
2918
2920
  const [inputValue, setInputValue] = React.useState(initialValue);
@@ -2940,16 +2942,16 @@ function Combobox({
2940
2942
  }
2941
2943
  setCurrentOptions(children);
2942
2944
  }
2943
- onToggle == null ? void 0 : onToggle(newState);
2945
+ onToggle == null || onToggle(newState);
2944
2946
  }, [children, disabled, isControlled, labelFromSelected, onToggle, openState, selectionType, setFocusedIndex]);
2945
2947
  const handleChange = React.useCallback(value => {
2946
2948
  if (value !== valueState) {
2947
2949
  setSelectedValue(value);
2948
- onChange == null ? void 0 : onChange(value);
2950
+ onChange == null || onChange(value);
2949
2951
  }
2950
2952
  if (selectionType === "single" && typeof value === "string") {
2951
2953
  var _renderList$find2;
2952
- const itemFromSelected = (_renderList$find2 = renderList.find(item => item.props.value === value)) == null ? void 0 : _renderList$find2.props;
2954
+ const itemFromSelected = (_renderList$find2 = renderList.find(item => item.props.value === value)) == null ? undefined : _renderList$find2.props;
2953
2955
  const labelFromSelected = itemFromSelected ? getLabel(itemFromSelected) : "";
2954
2956
  updateOpenState(false, labelFromSelected);
2955
2957
  } else if (Array.isArray(value)) {
@@ -3003,20 +3005,20 @@ function Combobox({
3003
3005
  e.stopPropagation();
3004
3006
  setInputValue("");
3005
3007
  setSelected("");
3006
- onChange == null ? void 0 : onChange("");
3007
- (_comboboxRef$current = comboboxRef.current) == null ? void 0 : _comboboxRef$current.focus();
3008
+ onChange == null || onChange("");
3009
+ (_comboboxRef$current = comboboxRef.current) == null || _comboboxRef$current.focus();
3008
3010
  }, [onChange, setSelected]);
3009
3011
  React.useEffect(() => {
3010
3012
  if (openState) {
3011
3013
  var _comboboxRef$current2;
3012
- (_comboboxRef$current2 = comboboxRef.current) == null ? void 0 : _comboboxRef$current2.focus();
3014
+ (_comboboxRef$current2 = comboboxRef.current) == null || _comboboxRef$current2.focus();
3013
3015
  }
3014
3016
  }, [openState]);
3015
3017
  const selectedLabels = React.useMemo(() => {
3016
3018
  if (Array.isArray(selected)) {
3017
3019
  return selected.map(value => {
3018
3020
  const item = children.find(item => item.props.value === value);
3019
- return item ? getLabel(item == null ? void 0 : item.props) : "";
3021
+ return item ? getLabel(item == null ? undefined : item.props) : "";
3020
3022
  });
3021
3023
  }
3022
3024
  return [labelFromSelected];
@@ -3037,7 +3039,7 @@ function Combobox({
3037
3039
  };
3038
3040
  const pillIdPrefix = `${uniqueId}-pill-`;
3039
3041
  const textFieldId = useId();
3040
- const currentActiveDescendant = !openState ? undefined : focusedIndex >= 0 ? (_renderList$focusedIn = renderList[focusedIndex]) == null ? void 0 : (_renderList$focusedIn2 = _renderList$focusedIn.props) == null ? void 0 : _renderList$focusedIn2.id : pillIdPrefix + focusedMultiSelectIndex;
3042
+ const currentActiveDescendant = !openState ? undefined : focusedIndex >= 0 ? (_renderList$focusedIn = renderList[focusedIndex]) == null || (_renderList$focusedIn = _renderList$focusedIn.props) == null ? undefined : _renderList$focusedIn.id : pillIdPrefix + focusedMultiSelectIndex;
3041
3043
  const controlledWidget = !openState ? undefined : focusedIndex >= 0 ? uniqueId : pillIdPrefix;
3042
3044
  return React.createElement(React.Fragment, null, React.createElement(View, {
3043
3045
  onClick: () => {
@@ -3116,13 +3118,13 @@ function Combobox({
3116
3118
  "aria-label": labels.comboboxButton
3117
3119
  })), openState && React.createElement(DropdownPopper, {
3118
3120
  alignment: "left",
3119
- referenceElement: rootNodeRef == null ? void 0 : rootNodeRef.current
3121
+ referenceElement: rootNodeRef == null ? undefined : rootNodeRef.current
3120
3122
  }, isReferenceHidden => {
3121
3123
  var _rootNodeRef$current, _rootNodeRef$current2;
3122
3124
  return React.createElement(React.Fragment, null, renderList.length === 0 ? React.createElement(DetailCell, {
3123
3125
  title: labels.noItems,
3124
3126
  style: [styles.listbox, {
3125
- minWidth: rootNodeRef == null ? void 0 : (_rootNodeRef$current = rootNodeRef.current) == null ? void 0 : _rootNodeRef$current.offsetWidth
3127
+ minWidth: rootNodeRef == null || (_rootNodeRef$current = rootNodeRef.current) == null ? undefined : _rootNodeRef$current.offsetWidth
3126
3128
  }],
3127
3129
  horizontalRule: "none"
3128
3130
  }) : React.createElement(Listbox, {
@@ -3130,7 +3132,7 @@ function Combobox({
3130
3132
  tabIndex: -1,
3131
3133
  selectionType: selectionType,
3132
3134
  style: [styles.listbox, isReferenceHidden && styles.hidden, {
3133
- minWidth: rootNodeRef == null ? void 0 : (_rootNodeRef$current2 = rootNodeRef.current) == null ? void 0 : _rootNodeRef$current2.offsetWidth
3135
+ minWidth: rootNodeRef == null || (_rootNodeRef$current2 = rootNodeRef.current) == null ? undefined : _rootNodeRef$current2.offsetWidth
3134
3136
  }],
3135
3137
  testId: testId ? `${testId}-listbox` : undefined,
3136
3138
  "aria-label": labels.listbox,