@khanacademy/wonder-blocks-dropdown 5.8.0 → 6.0.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/CHANGELOG.md CHANGED
@@ -1,5 +1,32 @@
1
1
  # @khanacademy/wonder-blocks-dropdown
2
2
 
3
+ ## 6.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - e6abdd17: Upgrade to React 18
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [e6abdd17]
12
+ - @khanacademy/wonder-blocks-timing@6.0.0
13
+ - @khanacademy/wonder-blocks-core@8.0.0
14
+ - @khanacademy/wonder-blocks-cell@4.0.0
15
+ - @khanacademy/wonder-blocks-clickable@5.0.0
16
+ - @khanacademy/wonder-blocks-icon@5.0.0
17
+ - @khanacademy/wonder-blocks-layout@3.0.0
18
+ - @khanacademy/wonder-blocks-modal@6.0.0
19
+ - @khanacademy/wonder-blocks-pill@3.0.0
20
+ - @khanacademy/wonder-blocks-search-field@3.0.0
21
+ - @khanacademy/wonder-blocks-tokens@3.0.0
22
+ - @khanacademy/wonder-blocks-typography@3.0.0
23
+
24
+ ## 5.8.1
25
+
26
+ ### Patch Changes
27
+
28
+ - c8b5b2e2: [MultiSelect and SingleSelect] Remove `showOpenerLabelAsText` from sharedProps that are passed to SelectOpener
29
+
3
30
  ## 5.8.0
4
31
 
5
32
  ### Minor Changes
@@ -1,4 +1,4 @@
1
- /// <reference types="react" />
1
+ import * as React from "react";
2
2
  import { ComboboxLabels, MaybeValueOrValues, OptionItemComponent } from "../util/types";
3
3
  type Props = {
4
4
  /**
@@ -48,5 +48,5 @@ type Props = {
48
48
  *
49
49
  * @see https://bugs.webkit.org/show_bug.cgi?id=167671
50
50
  */
51
- export declare function ComboboxLiveRegion({ focusedIndex, focusedMultiSelectIndex, labels, selectedLabels, opened, options, selected, selectionType, testId, }: Props): JSX.Element;
51
+ export declare function ComboboxLiveRegion({ focusedIndex, focusedMultiSelectIndex, labels, selectedLabels, opened, options, selected, selectionType, testId, }: Props): React.JSX.Element;
52
52
  export {};
@@ -107,5 +107,5 @@ type Props = {
107
107
  * Open button (🔽) is pressed.
108
108
  * - It is displayed when the combobox receives focus.
109
109
  */
110
- export default function Combobox({ autoComplete, children, disabled, error, id, labels, onChange, onToggle, opened, placeholder, selectionType, startIcon, testId, value, }: Props): JSX.Element;
110
+ export default function Combobox({ autoComplete, children, disabled, error, id, labels, onChange, onToggle, opened, placeholder, selectionType, startIcon, testId, value, }: Props): React.JSX.Element;
111
111
  export {};
@@ -6,7 +6,7 @@ declare const _default: {
6
6
  data: DropdownItem[];
7
7
  width?: number | null | undefined;
8
8
  listRef?: React.RefObject<List<any>> | undefined;
9
- }): JSX.Element;
9
+ }): React.JSX.Element;
10
10
  displayName: string;
11
11
  };
12
12
  export default _default;
@@ -1,4 +1,4 @@
1
- /// <reference types="react" />
1
+ import * as React from "react";
2
2
  import { StyleType } from "@khanacademy/wonder-blocks-core";
3
3
  import { MaybeValueOrValues, OptionItemComponent } from "../util/types";
4
4
  type Props = {
@@ -81,5 +81,5 @@ type Props = {
81
81
  * </Listbox>
82
82
  * ```
83
83
  */
84
- export default function Listbox(props: Props): JSX.Element;
84
+ export default function Listbox(props: Props): React.JSX.Element;
85
85
  export {};
package/dist/es/index.js CHANGED
@@ -825,13 +825,13 @@ class DropdownCore extends React.Component {
825
825
  }
826
826
  constructor(props) {
827
827
  super(props);
828
- this.focusedIndex = void 0;
829
- this.focusedOriginalIndex = void 0;
830
- this.itemsClicked = void 0;
831
828
  this.popperElement = void 0;
832
829
  this.virtualizedListRef = void 0;
833
830
  this.handleKeyDownDebounced = void 0;
834
831
  this.textSuggestion = void 0;
832
+ this.focusedIndex = -1;
833
+ this.focusedOriginalIndex = -1;
834
+ this.itemsClicked = false;
835
835
  this.searchFieldRef = React.createRef();
836
836
  this.handleInteract = event => {
837
837
  const {
@@ -1075,18 +1075,37 @@ class DropdownCore extends React.Component {
1075
1075
  }
1076
1076
  focusCurrentItem(onFocus) {
1077
1077
  const focusedItemRef = this.state.itemRefs[this.focusedIndex];
1078
- if (focusedItemRef) {
1079
- if (this.virtualizedListRef.current) {
1080
- this.virtualizedListRef.current.scrollToItem(focusedItemRef.originalIndex);
1078
+ if (!focusedItemRef) {
1079
+ return;
1080
+ }
1081
+ const {
1082
+ current: virtualizedList
1083
+ } = this.virtualizedListRef;
1084
+ if (virtualizedList) {
1085
+ virtualizedList.scrollToItem(focusedItemRef.originalIndex);
1086
+ }
1087
+ const focusNode = () => {
1088
+ if (!this.props.open) {
1089
+ return;
1090
+ }
1091
+ const currentFocusedItemRef = this.state.itemRefs[this.focusedIndex];
1092
+ const node = ReactDOM.findDOMNode(currentFocusedItemRef.ref.current);
1093
+ if (!node && this.shouldVirtualizeList()) {
1094
+ this.props.schedule.animationFrame(focusNode);
1095
+ return;
1081
1096
  }
1082
- const node = ReactDOM.findDOMNode(focusedItemRef.ref.current);
1083
1097
  if (node) {
1084
1098
  node.focus();
1085
- this.focusedOriginalIndex = focusedItemRef.originalIndex;
1099
+ this.focusedOriginalIndex = currentFocusedItemRef.originalIndex;
1086
1100
  if (onFocus) {
1087
1101
  onFocus(node);
1088
1102
  }
1089
1103
  }
1104
+ };
1105
+ if (this.shouldVirtualizeList()) {
1106
+ this.props.schedule.animationFrame(focusNode);
1107
+ } else {
1108
+ focusNode();
1090
1109
  }
1091
1110
  }
1092
1111
  focusSearchField() {
@@ -1106,7 +1125,7 @@ class DropdownCore extends React.Component {
1106
1125
  return this.focusSearchField();
1107
1126
  }
1108
1127
  this.focusedIndex = this.state.itemRefs.length - 1;
1109
- } else {
1128
+ } else if (!this.isSearchFieldFocused()) {
1110
1129
  this.focusedIndex -= 1;
1111
1130
  }
1112
1131
  this.scheduleToFocusCurrentItem();
@@ -1117,7 +1136,7 @@ class DropdownCore extends React.Component {
1117
1136
  return this.focusSearchField();
1118
1137
  }
1119
1138
  this.focusedIndex = 0;
1120
- } else {
1139
+ } else if (!this.isSearchFieldFocused()) {
1121
1140
  this.focusedIndex += 1;
1122
1141
  }
1123
1142
  this.scheduleToFocusCurrentItem();
@@ -1199,7 +1218,7 @@ class DropdownCore extends React.Component {
1199
1218
  const focusIndex = focusCounter - 1;
1200
1219
  return _extends({}, item, {
1201
1220
  role: populatedProps.role || itemRole,
1202
- ref: item.focusable ? this.state.itemRefs[focusIndex] ? this.state.itemRefs[focusIndex].ref : null : null,
1221
+ ref: item.focusable && this.state.itemRefs[focusIndex] ? this.state.itemRefs[focusIndex].ref : null,
1203
1222
  onClick: () => {
1204
1223
  this.handleItemClick(focusIndex, item);
1205
1224
  }
@@ -1868,7 +1887,7 @@ const _generateStyles = (light, placeholder, error) => {
1868
1887
  return stateStyles[styleKey];
1869
1888
  };
1870
1889
 
1871
- const _excluded$1 = ["children", "error", "id", "light", "opener", "placeholder", "selectedValue", "testId", "alignment", "autoFocus", "dropdownStyle", "enableTypeAhead", "isFilterable", "labels", "onChange", "onToggle", "opened", "style", "className", "aria-invalid", "aria-required", "showOpenerLabelAsText"];
1890
+ const _excluded$1 = ["children", "error", "id", "light", "opener", "placeholder", "selectedValue", "testId", "showOpenerLabelAsText", "alignment", "autoFocus", "dropdownStyle", "enableTypeAhead", "isFilterable", "labels", "onChange", "onToggle", "opened", "style", "className", "aria-invalid", "aria-required"];
1872
1891
  class SingleSelect extends React.Component {
1873
1892
  constructor(props) {
1874
1893
  super(props);
@@ -2080,7 +2099,7 @@ SingleSelect.defaultProps = {
2080
2099
  showOpenerLabelAsText: true
2081
2100
  };
2082
2101
 
2083
- const _excluded = ["id", "light", "opener", "testId", "alignment", "dropdownStyle", "implicitAllEnabled", "isFilterable", "labels", "onChange", "onToggle", "opened", "selectedValues", "shortcuts", "style", "className", "aria-invalid", "aria-required"];
2102
+ const _excluded = ["id", "light", "opener", "testId", "alignment", "dropdownStyle", "implicitAllEnabled", "isFilterable", "labels", "onChange", "onToggle", "opened", "selectedValues", "shortcuts", "style", "className", "aria-invalid", "aria-required", "showOpenerLabelAsText"];
2084
2103
  class MultiSelect extends React.Component {
2085
2104
  constructor(props) {
2086
2105
  super(props);
@@ -68,7 +68,7 @@ export declare function useListbox({ children: options, disabled, disableSpaceSe
68
68
  rightAccessory?: React.ReactNode;
69
69
  subtitle1?: import("@khanacademy/wonder-blocks-cell").TypographyText | undefined;
70
70
  subtitle2?: import("@khanacademy/wonder-blocks-cell").TypographyText | undefined;
71
- }, keyof import("@khanacademy/wonder-blocks-core").AriaAttributes | "label" | "style" | "leftAccessory" | "rightAccessory" | "testId" | "onClick" | "subtitle1" | "id" | "subtitle2" | "value" | "labelAsText" | "variant" | "parentComponent"> & {
71
+ }, keyof import("@khanacademy/wonder-blocks-core").AriaAttributes | "style" | "label" | "leftAccessory" | "rightAccessory" | "testId" | "onClick" | "subtitle1" | "subtitle2" | "value" | "id" | "labelAsText" | "variant" | "parentComponent"> & {
72
72
  selected?: boolean | undefined;
73
73
  role?: "menuitem" | "menuitemcheckbox" | "option" | undefined;
74
74
  disabled?: boolean | undefined;
package/dist/index.js CHANGED
@@ -861,13 +861,13 @@ class DropdownCore extends React__namespace.Component {
861
861
  }
862
862
  constructor(props) {
863
863
  super(props);
864
- this.focusedIndex = void 0;
865
- this.focusedOriginalIndex = void 0;
866
- this.itemsClicked = void 0;
867
864
  this.popperElement = void 0;
868
865
  this.virtualizedListRef = void 0;
869
866
  this.handleKeyDownDebounced = void 0;
870
867
  this.textSuggestion = void 0;
868
+ this.focusedIndex = -1;
869
+ this.focusedOriginalIndex = -1;
870
+ this.itemsClicked = false;
871
871
  this.searchFieldRef = React__namespace.createRef();
872
872
  this.handleInteract = event => {
873
873
  const {
@@ -1111,18 +1111,37 @@ class DropdownCore extends React__namespace.Component {
1111
1111
  }
1112
1112
  focusCurrentItem(onFocus) {
1113
1113
  const focusedItemRef = this.state.itemRefs[this.focusedIndex];
1114
- if (focusedItemRef) {
1115
- if (this.virtualizedListRef.current) {
1116
- this.virtualizedListRef.current.scrollToItem(focusedItemRef.originalIndex);
1114
+ if (!focusedItemRef) {
1115
+ return;
1116
+ }
1117
+ const {
1118
+ current: virtualizedList
1119
+ } = this.virtualizedListRef;
1120
+ if (virtualizedList) {
1121
+ virtualizedList.scrollToItem(focusedItemRef.originalIndex);
1122
+ }
1123
+ const focusNode = () => {
1124
+ if (!this.props.open) {
1125
+ return;
1126
+ }
1127
+ const currentFocusedItemRef = this.state.itemRefs[this.focusedIndex];
1128
+ const node = ReactDOM__namespace.findDOMNode(currentFocusedItemRef.ref.current);
1129
+ if (!node && this.shouldVirtualizeList()) {
1130
+ this.props.schedule.animationFrame(focusNode);
1131
+ return;
1117
1132
  }
1118
- const node = ReactDOM__namespace.findDOMNode(focusedItemRef.ref.current);
1119
1133
  if (node) {
1120
1134
  node.focus();
1121
- this.focusedOriginalIndex = focusedItemRef.originalIndex;
1135
+ this.focusedOriginalIndex = currentFocusedItemRef.originalIndex;
1122
1136
  if (onFocus) {
1123
1137
  onFocus(node);
1124
1138
  }
1125
1139
  }
1140
+ };
1141
+ if (this.shouldVirtualizeList()) {
1142
+ this.props.schedule.animationFrame(focusNode);
1143
+ } else {
1144
+ focusNode();
1126
1145
  }
1127
1146
  }
1128
1147
  focusSearchField() {
@@ -1142,7 +1161,7 @@ class DropdownCore extends React__namespace.Component {
1142
1161
  return this.focusSearchField();
1143
1162
  }
1144
1163
  this.focusedIndex = this.state.itemRefs.length - 1;
1145
- } else {
1164
+ } else if (!this.isSearchFieldFocused()) {
1146
1165
  this.focusedIndex -= 1;
1147
1166
  }
1148
1167
  this.scheduleToFocusCurrentItem();
@@ -1153,7 +1172,7 @@ class DropdownCore extends React__namespace.Component {
1153
1172
  return this.focusSearchField();
1154
1173
  }
1155
1174
  this.focusedIndex = 0;
1156
- } else {
1175
+ } else if (!this.isSearchFieldFocused()) {
1157
1176
  this.focusedIndex += 1;
1158
1177
  }
1159
1178
  this.scheduleToFocusCurrentItem();
@@ -1235,7 +1254,7 @@ class DropdownCore extends React__namespace.Component {
1235
1254
  const focusIndex = focusCounter - 1;
1236
1255
  return _extends__default["default"]({}, item, {
1237
1256
  role: populatedProps.role || itemRole,
1238
- ref: item.focusable ? this.state.itemRefs[focusIndex] ? this.state.itemRefs[focusIndex].ref : null : null,
1257
+ ref: item.focusable && this.state.itemRefs[focusIndex] ? this.state.itemRefs[focusIndex].ref : null,
1239
1258
  onClick: () => {
1240
1259
  this.handleItemClick(focusIndex, item);
1241
1260
  }
@@ -1904,7 +1923,7 @@ const _generateStyles = (light, placeholder, error) => {
1904
1923
  return stateStyles[styleKey];
1905
1924
  };
1906
1925
 
1907
- const _excluded$1 = ["children", "error", "id", "light", "opener", "placeholder", "selectedValue", "testId", "alignment", "autoFocus", "dropdownStyle", "enableTypeAhead", "isFilterable", "labels", "onChange", "onToggle", "opened", "style", "className", "aria-invalid", "aria-required", "showOpenerLabelAsText"];
1926
+ const _excluded$1 = ["children", "error", "id", "light", "opener", "placeholder", "selectedValue", "testId", "showOpenerLabelAsText", "alignment", "autoFocus", "dropdownStyle", "enableTypeAhead", "isFilterable", "labels", "onChange", "onToggle", "opened", "style", "className", "aria-invalid", "aria-required"];
1908
1927
  class SingleSelect extends React__namespace.Component {
1909
1928
  constructor(props) {
1910
1929
  super(props);
@@ -2116,7 +2135,7 @@ SingleSelect.defaultProps = {
2116
2135
  showOpenerLabelAsText: true
2117
2136
  };
2118
2137
 
2119
- const _excluded = ["id", "light", "opener", "testId", "alignment", "dropdownStyle", "implicitAllEnabled", "isFilterable", "labels", "onChange", "onToggle", "opened", "selectedValues", "shortcuts", "style", "className", "aria-invalid", "aria-required"];
2138
+ const _excluded = ["id", "light", "opener", "testId", "alignment", "dropdownStyle", "implicitAllEnabled", "isFilterable", "labels", "onChange", "onToggle", "opened", "selectedValues", "shortcuts", "style", "className", "aria-invalid", "aria-required", "showOpenerLabelAsText"];
2120
2139
  class MultiSelect extends React__namespace.Component {
2121
2140
  constructor(props) {
2122
2141
  super(props);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@khanacademy/wonder-blocks-dropdown",
3
- "version": "5.8.0",
3
+ "version": "6.0.0",
4
4
  "design": "v1",
5
5
  "description": "Dropdown variants for Wonder Blocks.",
6
6
  "main": "dist/index.js",
@@ -16,31 +16,31 @@
16
16
  },
17
17
  "dependencies": {
18
18
  "@babel/runtime": "^7.18.6",
19
- "@khanacademy/wonder-blocks-cell": "^3.4.6",
20
- "@khanacademy/wonder-blocks-clickable": "^4.2.9",
21
- "@khanacademy/wonder-blocks-core": "^7.0.1",
22
- "@khanacademy/wonder-blocks-icon": "^4.2.0",
23
- "@khanacademy/wonder-blocks-layout": "^2.2.2",
24
- "@khanacademy/wonder-blocks-modal": "^5.1.17",
25
- "@khanacademy/wonder-blocks-pill": "^2.5.3",
26
- "@khanacademy/wonder-blocks-search-field": "^2.3.6",
27
- "@khanacademy/wonder-blocks-timing": "^5.0.2",
28
- "@khanacademy/wonder-blocks-tokens": "^2.1.0",
29
- "@khanacademy/wonder-blocks-typography": "^2.1.16"
19
+ "@khanacademy/wonder-blocks-cell": "^4.0.0",
20
+ "@khanacademy/wonder-blocks-clickable": "^5.0.0",
21
+ "@khanacademy/wonder-blocks-core": "^8.0.0",
22
+ "@khanacademy/wonder-blocks-icon": "^5.0.0",
23
+ "@khanacademy/wonder-blocks-layout": "^3.0.0",
24
+ "@khanacademy/wonder-blocks-modal": "^6.0.0",
25
+ "@khanacademy/wonder-blocks-pill": "^3.0.0",
26
+ "@khanacademy/wonder-blocks-search-field": "^3.0.0",
27
+ "@khanacademy/wonder-blocks-timing": "^6.0.0",
28
+ "@khanacademy/wonder-blocks-tokens": "^3.0.0",
29
+ "@khanacademy/wonder-blocks-typography": "^3.0.0"
30
30
  },
31
31
  "peerDependencies": {
32
32
  "@phosphor-icons/core": "^2.0.2",
33
33
  "@popperjs/core": "^2.10.1",
34
34
  "aphrodite": "^1.2.5",
35
- "react": "16.14.0",
36
- "react-dom": "16.14.0",
35
+ "react": "18.2.0",
36
+ "react-dom": "18.2.0",
37
37
  "react-popper": "^2.0.0",
38
- "react-router": "5.2.1",
39
- "react-router-dom": "5.3.0",
40
- "react-window": "^1.8.5"
38
+ "react-router": "5.3.4",
39
+ "react-router-dom": "5.3.4",
40
+ "react-window": "^1.8.10"
41
41
  },
42
42
  "devDependencies": {
43
- "@khanacademy/wonder-blocks-button": "^6.3.12",
44
- "@khanacademy/wb-dev-build-settings": "^1.0.1"
43
+ "@khanacademy/wonder-blocks-button": "^7.0.0",
44
+ "@khanacademy/wb-dev-build-settings": "^2.0.0"
45
45
  }
46
46
  }