@khanacademy/wonder-blocks-dropdown 5.3.8 → 5.4.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/dist/index.js CHANGED
@@ -522,7 +522,10 @@ class DropdownOpener extends React__namespace.Component {
522
522
  disabled,
523
523
  testId,
524
524
  text,
525
- opened
525
+ opened,
526
+ "aria-controls": ariaControls,
527
+ "aria-haspopup": ariaHasPopUp,
528
+ id
526
529
  } = this.props;
527
530
  const renderedChildren = this.props.children(_extends({}, eventState, {
528
531
  text,
@@ -532,6 +535,10 @@ class DropdownOpener extends React__namespace.Component {
532
535
  const childrenTestId = this.getTestIdFromProps(childrenProps);
533
536
  return React__namespace.cloneElement(renderedChildren, _extends({}, clickableChildrenProps, {
534
537
  disabled,
538
+ "aria-controls": ariaControls,
539
+ id,
540
+ "aria-expanded": opened ? "true" : "false",
541
+ "aria-haspopup": ariaHasPopUp,
535
542
  onClick: childrenProps.onClick ? e => {
536
543
  childrenProps.onClick(e);
537
544
  clickableChildrenProps.onClick(e);
@@ -1199,7 +1206,7 @@ class DropdownCore extends React__namespace.Component {
1199
1206
  this.handleItemClick(focusIndex, item);
1200
1207
  },
1201
1208
  ref: focusable ? currentRef : null,
1202
- role: itemRole
1209
+ role: populatedProps.role || itemRole
1203
1210
  }));
1204
1211
  });
1205
1212
  }
@@ -1207,12 +1214,15 @@ class DropdownCore extends React__namespace.Component {
1207
1214
  let focusCounter = 0;
1208
1215
  const itemRole = this.getItemRole();
1209
1216
  return this.props.items.map((item, index) => {
1217
+ const {
1218
+ populatedProps
1219
+ } = item;
1210
1220
  if (!SeparatorItem.isClassOf(item.component) && item.focusable) {
1211
1221
  focusCounter += 1;
1212
1222
  }
1213
1223
  const focusIndex = focusCounter - 1;
1214
1224
  return _extends({}, item, {
1215
- role: itemRole,
1225
+ role: populatedProps.role || itemRole,
1216
1226
  ref: item.focusable ? this.state.itemRefs[focusIndex] ? this.state.itemRefs[focusIndex].ref : null : null,
1217
1227
  onClick: () => {
1218
1228
  this.handleItemClick(focusIndex, item);
@@ -1251,7 +1261,8 @@ class DropdownCore extends React__namespace.Component {
1251
1261
  isFilterable,
1252
1262
  light,
1253
1263
  openerElement,
1254
- role
1264
+ role,
1265
+ id
1255
1266
  } = this.props;
1256
1267
  const openerStyle = openerElement && window.getComputedStyle(openerElement);
1257
1268
  const minDropdownWidth = openerStyle ? openerStyle.getPropertyValue("width") : 0;
@@ -1260,6 +1271,7 @@ class DropdownCore extends React__namespace.Component {
1260
1271
  style: [styles$4.dropdown, light && styles$4.light, isReferenceHidden && styles$4.hidden, dropdownStyle],
1261
1272
  testId: "dropdown-core-container"
1262
1273
  }, isFilterable && this.renderSearchField(), React__namespace.createElement(wonderBlocksCore.View, {
1274
+ id: id,
1263
1275
  role: role,
1264
1276
  style: [styles$4.listboxOrMenu, {
1265
1277
  minWidth: minDropdownWidth
@@ -1577,11 +1589,15 @@ class ActionMenu extends React__namespace.Component {
1577
1589
  }
1578
1590
  });
1579
1591
  } else if (OptionItem.isClassOf(item)) {
1592
+ const selected = selectedValues ? selectedValues.includes(value) : false;
1580
1593
  return _extends({}, itemObject, {
1581
1594
  populatedProps: {
1582
1595
  onToggle: this.handleOptionSelected,
1583
- selected: selectedValues ? selectedValues.includes(value) : false,
1584
- variant: "check"
1596
+ selected,
1597
+ variant: "check",
1598
+ role: "menuitemcheckbox",
1599
+ "aria-checked": selected,
1600
+ "aria-selected": undefined
1585
1601
  }
1586
1602
  });
1587
1603
  } else {
@@ -1589,14 +1605,21 @@ class ActionMenu extends React__namespace.Component {
1589
1605
  }
1590
1606
  });
1591
1607
  }
1592
- renderOpener(numItems) {
1608
+ renderOpener(numItems, dropdownId) {
1593
1609
  const {
1594
1610
  disabled,
1595
1611
  menuText,
1596
1612
  opener,
1597
- testId
1613
+ testId,
1614
+ id
1598
1615
  } = this.props;
1599
- return React__namespace.createElement(DropdownOpener, {
1616
+ return React__namespace.createElement(wonderBlocksCore.IDProvider, {
1617
+ id: id,
1618
+ scope: "action-menu-opener"
1619
+ }, uniqueOpenerId => React__namespace.createElement(DropdownOpener, {
1620
+ id: uniqueOpenerId,
1621
+ "aria-controls": dropdownId,
1622
+ "aria-haspopup": "menu",
1600
1623
  onClick: this.handleClick,
1601
1624
  disabled: numItems === 0 || disabled,
1602
1625
  text: menuText,
@@ -1613,29 +1636,33 @@ class ActionMenu extends React__namespace.Component {
1613
1636
  opened: !!opened,
1614
1637
  testId: testId
1615
1638
  }), menuText);
1616
- });
1639
+ }));
1617
1640
  }
1618
1641
  render() {
1619
1642
  const {
1620
1643
  alignment,
1621
1644
  dropdownStyle,
1622
1645
  style,
1623
- className
1646
+ className,
1647
+ dropdownId
1624
1648
  } = this.props;
1625
1649
  const items = this.getMenuItems();
1626
- const dropdownOpener = this.renderOpener(items.length);
1627
- return React__namespace.createElement(DropdownCore$1, {
1650
+ return React__namespace.createElement(wonderBlocksCore.IDProvider, {
1651
+ id: dropdownId,
1652
+ scope: "action-menu-dropdown"
1653
+ }, uniqueDropdownId => React__namespace.createElement(DropdownCore$1, {
1654
+ id: uniqueDropdownId,
1628
1655
  role: "menu",
1629
1656
  style: style,
1630
1657
  className: className,
1631
- opener: dropdownOpener,
1658
+ opener: this.renderOpener(items.length, uniqueDropdownId),
1632
1659
  alignment: alignment,
1633
1660
  open: this.state.opened,
1634
1661
  items: items,
1635
1662
  openerElement: this.openerElement,
1636
1663
  onOpenChanged: this.handleOpenChanged,
1637
1664
  dropdownStyle: [styles$2.menuTopSpace, dropdownStyle]
1638
- });
1665
+ }));
1639
1666
  }
1640
1667
  }
1641
1668
  ActionMenu.defaultProps = {
@@ -1834,13 +1861,13 @@ const _generateStyles = (light, placeholder, error) => {
1834
1861
  newStyles = {
1835
1862
  default: {
1836
1863
  background: error ? tokens__namespace.color.fadedRed8 : tokens__namespace.color.white,
1837
- borderColor: error ? tokens__namespace.color.red : tokens__namespace.color.offBlack16,
1864
+ borderColor: error ? tokens__namespace.color.red : tokens__namespace.color.offBlack50,
1838
1865
  borderWidth: tokens__namespace.border.width.hairline,
1839
1866
  color: placeholder ? tokens__namespace.color.offBlack64 : tokens__namespace.color.offBlack,
1840
1867
  ":hover:not([aria-disabled=true])": focusHoverStyling,
1841
1868
  ["@media not (hover: hover)"]: {
1842
1869
  ":hover:not([aria-disabled=true])": {
1843
- borderColor: error ? tokens__namespace.color.red : tokens__namespace.color.offBlack16,
1870
+ borderColor: error ? tokens__namespace.color.red : tokens__namespace.color.offBlack50,
1844
1871
  borderWidth: tokens__namespace.border.width.hairline,
1845
1872
  paddingLeft: tokens__namespace.spacing.medium_16,
1846
1873
  paddingRight: tokens__namespace.spacing.small_12
@@ -1962,7 +1989,7 @@ class SingleSelect extends React__namespace.Component {
1962
1989
  } = this.props;
1963
1990
  return this.mapOptionItemsToDropdownItems(isFilterable ? this.filterChildren(children) : children);
1964
1991
  }
1965
- renderOpener(isDisabled) {
1992
+ renderOpener(isDisabled, dropdownId) {
1966
1993
  const _this$props = this.props,
1967
1994
  {
1968
1995
  children,
@@ -1978,23 +2005,32 @@ class SingleSelect extends React__namespace.Component {
1978
2005
  const items = React__namespace.Children.toArray(children);
1979
2006
  const selectedItem = items.find(option => option.props.value === selectedValue);
1980
2007
  const menuText = selectedItem ? getLabel(selectedItem.props) : placeholder;
1981
- const dropdownOpener = opener ? React__namespace.createElement(DropdownOpener, {
1982
- onClick: this.handleClick,
1983
- disabled: isDisabled,
1984
- ref: this.handleOpenerRef,
1985
- text: menuText,
1986
- opened: this.state.open
1987
- }, opener) : React__namespace.createElement(SelectOpener, _extends({}, sharedProps, {
1988
- disabled: isDisabled,
2008
+ const dropdownOpener = React__namespace.createElement(wonderBlocksCore.IDProvider, {
1989
2009
  id: id,
1990
- error: error,
1991
- isPlaceholder: !selectedItem,
1992
- light: light,
1993
- onOpenChanged: this.handleOpenChanged,
1994
- open: this.state.open,
1995
- ref: this.handleOpenerRef,
1996
- testId: testId
1997
- }), menuText);
2010
+ scope: "single-select-opener"
2011
+ }, uniqueOpenerId => {
2012
+ return opener ? React__namespace.createElement(DropdownOpener, {
2013
+ id: uniqueOpenerId,
2014
+ "aria-controls": dropdownId,
2015
+ "aria-haspopup": "listbox",
2016
+ onClick: this.handleClick,
2017
+ disabled: isDisabled,
2018
+ ref: this.handleOpenerRef,
2019
+ text: menuText,
2020
+ opened: this.state.open
2021
+ }, opener) : React__namespace.createElement(SelectOpener, _extends({}, sharedProps, {
2022
+ "aria-controls": dropdownId,
2023
+ disabled: isDisabled,
2024
+ id: uniqueOpenerId,
2025
+ error: error,
2026
+ isPlaceholder: !selectedItem,
2027
+ light: light,
2028
+ onOpenChanged: this.handleOpenChanged,
2029
+ open: this.state.open,
2030
+ ref: this.handleOpenerRef,
2031
+ testId: testId
2032
+ }), menuText);
2033
+ });
1998
2034
  return dropdownOpener;
1999
2035
  }
2000
2036
  render() {
@@ -2011,7 +2047,8 @@ class SingleSelect extends React__namespace.Component {
2011
2047
  style,
2012
2048
  "aria-invalid": ariaInvalid,
2013
2049
  "aria-required": ariaRequired,
2014
- disabled
2050
+ disabled,
2051
+ dropdownId
2015
2052
  } = this.props;
2016
2053
  const {
2017
2054
  searchText
@@ -2020,8 +2057,11 @@ class SingleSelect extends React__namespace.Component {
2020
2057
  const numEnabledOptions = allChildren.filter(option => !option.props.disabled).length;
2021
2058
  const items = this.getMenuItems(allChildren);
2022
2059
  const isDisabled = numEnabledOptions === 0 || disabled;
2023
- const opener = this.renderOpener(isDisabled);
2024
- return React__namespace.createElement(DropdownCore$1, {
2060
+ return React__namespace.createElement(wonderBlocksCore.IDProvider, {
2061
+ id: dropdownId,
2062
+ scope: "single-select-dropdown"
2063
+ }, uniqueDropdownId => React__namespace.createElement(DropdownCore$1, {
2064
+ id: uniqueDropdownId,
2025
2065
  role: "listbox",
2026
2066
  selectionType: "single",
2027
2067
  alignment: alignment,
@@ -2033,7 +2073,7 @@ class SingleSelect extends React__namespace.Component {
2033
2073
  light: light,
2034
2074
  onOpenChanged: this.handleOpenChanged,
2035
2075
  open: this.state.open,
2036
- opener: opener,
2076
+ opener: this.renderOpener(isDisabled, uniqueDropdownId),
2037
2077
  openerElement: this.state.openerElement,
2038
2078
  style: style,
2039
2079
  className: className,
@@ -2044,7 +2084,7 @@ class SingleSelect extends React__namespace.Component {
2044
2084
  "aria-invalid": ariaInvalid,
2045
2085
  "aria-required": ariaRequired,
2046
2086
  disabled: isDisabled
2047
- });
2087
+ }));
2048
2088
  }
2049
2089
  }
2050
2090
  SingleSelect.defaultProps = {
@@ -2269,7 +2309,7 @@ class MultiSelect extends React__namespace.Component {
2269
2309
  }
2270
2310
  return [...lastSelectedItems, ...restOfTheChildren.map(this.mapOptionItemToDropdownItem)];
2271
2311
  }
2272
- renderOpener(allChildren, isDisabled) {
2312
+ renderOpener(allChildren, isDisabled, dropdownId) {
2273
2313
  const _this$props = this.props,
2274
2314
  {
2275
2315
  id,
@@ -2282,22 +2322,31 @@ class MultiSelect extends React__namespace.Component {
2282
2322
  noneSelected
2283
2323
  } = this.state.labels;
2284
2324
  const menuText = this.getMenuText(allChildren);
2285
- const dropdownOpener = opener ? React__namespace.createElement(DropdownOpener, {
2286
- onClick: this.handleClick,
2287
- disabled: isDisabled,
2288
- ref: this.handleOpenerRef,
2289
- text: menuText,
2290
- opened: this.state.open
2291
- }, opener) : React__namespace.createElement(SelectOpener, _extends({}, sharedProps, {
2292
- disabled: isDisabled,
2325
+ const dropdownOpener = React__namespace.createElement(wonderBlocksCore.IDProvider, {
2293
2326
  id: id,
2294
- isPlaceholder: menuText === noneSelected,
2295
- light: light,
2296
- onOpenChanged: this.handleOpenChanged,
2297
- open: this.state.open,
2298
- ref: this.handleOpenerRef,
2299
- testId: testId
2300
- }), menuText);
2327
+ scope: "multi-select-opener"
2328
+ }, uniqueOpenerId => {
2329
+ return opener ? React__namespace.createElement(DropdownOpener, {
2330
+ id: uniqueOpenerId,
2331
+ "aria-controls": dropdownId,
2332
+ "aria-haspopup": "listbox",
2333
+ onClick: this.handleClick,
2334
+ disabled: isDisabled,
2335
+ ref: this.handleOpenerRef,
2336
+ text: menuText,
2337
+ opened: this.state.open
2338
+ }, opener) : React__namespace.createElement(SelectOpener, _extends({}, sharedProps, {
2339
+ disabled: isDisabled,
2340
+ id: uniqueOpenerId,
2341
+ "aria-controls": dropdownId,
2342
+ isPlaceholder: menuText === noneSelected,
2343
+ light: light,
2344
+ onOpenChanged: this.handleOpenChanged,
2345
+ open: this.state.open,
2346
+ ref: this.handleOpenerRef,
2347
+ testId: testId
2348
+ }), menuText);
2349
+ });
2301
2350
  return dropdownOpener;
2302
2351
  }
2303
2352
  render() {
@@ -2311,7 +2360,8 @@ class MultiSelect extends React__namespace.Component {
2311
2360
  isFilterable,
2312
2361
  "aria-invalid": ariaInvalid,
2313
2362
  "aria-required": ariaRequired,
2314
- disabled
2363
+ disabled,
2364
+ dropdownId
2315
2365
  } = this.props;
2316
2366
  const {
2317
2367
  open,
@@ -2327,8 +2377,11 @@ class MultiSelect extends React__namespace.Component {
2327
2377
  const numEnabledOptions = allChildren.filter(option => !option.props.disabled).length;
2328
2378
  const filteredItems = this.getMenuItems(allChildren);
2329
2379
  const isDisabled = numEnabledOptions === 0 || disabled;
2330
- const opener = this.renderOpener(allChildren, isDisabled);
2331
- return React__namespace.createElement(DropdownCore$1, {
2380
+ return React__namespace.createElement(wonderBlocksCore.IDProvider, {
2381
+ id: dropdownId,
2382
+ scope: "multi-select-dropdown"
2383
+ }, uniqueDropdownId => React__namespace.createElement(DropdownCore$1, {
2384
+ id: uniqueDropdownId,
2332
2385
  role: "listbox",
2333
2386
  alignment: alignment,
2334
2387
  dropdownStyle: [isFilterable && filterableDropdownStyle, selectDropdownStyle, dropdownStyle],
@@ -2337,7 +2390,7 @@ class MultiSelect extends React__namespace.Component {
2337
2390
  light: light,
2338
2391
  onOpenChanged: this.handleOpenChanged,
2339
2392
  open: open,
2340
- opener: opener,
2393
+ opener: this.renderOpener(allChildren, isDisabled, uniqueDropdownId),
2341
2394
  openerElement: this.state.openerElement,
2342
2395
  selectionType: "multi",
2343
2396
  style: style,
@@ -2353,7 +2406,7 @@ class MultiSelect extends React__namespace.Component {
2353
2406
  "aria-invalid": ariaInvalid,
2354
2407
  "aria-required": ariaRequired,
2355
2408
  disabled: isDisabled
2356
- });
2409
+ }));
2357
2410
  }
2358
2411
  }
2359
2412
  MultiSelect.defaultProps = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@khanacademy/wonder-blocks-dropdown",
3
- "version": "5.3.8",
3
+ "version": "5.4.0",
4
4
  "design": "v1",
5
5
  "description": "Dropdown variants for Wonder Blocks.",
6
6
  "main": "dist/index.js",
@@ -16,13 +16,13 @@
16
16
  },
17
17
  "dependencies": {
18
18
  "@babel/runtime": "^7.18.6",
19
- "@khanacademy/wonder-blocks-cell": "^3.3.7",
20
- "@khanacademy/wonder-blocks-clickable": "^4.2.2",
19
+ "@khanacademy/wonder-blocks-cell": "^3.4.0",
20
+ "@khanacademy/wonder-blocks-clickable": "^4.2.3",
21
21
  "@khanacademy/wonder-blocks-core": "^6.4.1",
22
22
  "@khanacademy/wonder-blocks-icon": "^4.1.1",
23
23
  "@khanacademy/wonder-blocks-layout": "^2.1.0",
24
- "@khanacademy/wonder-blocks-modal": "^5.1.5",
25
- "@khanacademy/wonder-blocks-search-field": "^2.2.16",
24
+ "@khanacademy/wonder-blocks-modal": "^5.1.6",
25
+ "@khanacademy/wonder-blocks-search-field": "^2.2.18",
26
26
  "@khanacademy/wonder-blocks-timing": "^5.0.0",
27
27
  "@khanacademy/wonder-blocks-tokens": "^1.3.0",
28
28
  "@khanacademy/wonder-blocks-typography": "^2.1.12"
@@ -39,7 +39,7 @@
39
39
  "react-window": "^1.8.5"
40
40
  },
41
41
  "devDependencies": {
42
- "@khanacademy/wonder-blocks-button": "^6.3.2",
42
+ "@khanacademy/wonder-blocks-button": "^6.3.3",
43
43
  "@khanacademy/wb-dev-build-settings": "^1.0.0"
44
44
  }
45
45
  }