@khanacademy/wonder-blocks-dropdown 2.6.9 → 2.6.10

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,11 @@
1
1
  # @khanacademy/wonder-blocks-dropdown
2
2
 
3
+ ## 2.6.10
4
+
5
+ ### Patch Changes
6
+
7
+ - 0b94d616: Adds a max-height value to the dropdown menu to avoid displaying long lists that might cut off on small screen resolutions
8
+
3
9
  ## 2.6.9
4
10
 
5
11
  ### Patch Changes
package/dist/es/index.js CHANGED
@@ -31,14 +31,14 @@ const selectDropdownStyle = {
31
31
  marginBottom: Spacing.xSmall_8
32
32
  };
33
33
  const filterableDropdownStyle = {
34
- minHeight: 100,
35
- maxHeight: 384
34
+ minHeight: 100
36
35
  };
37
36
  const searchInputStyle = {
38
37
  margin: Spacing.xSmall_8,
39
38
  marginTop: Spacing.xxxSmall_4
40
39
  };
41
40
  const DROPDOWN_ITEM_HEIGHT = 40;
41
+ const MAX_VISIBLE_ITEMS = 9;
42
42
  const SEPARATOR_ITEM_HEIGHT = 9;
43
43
  const SEARCH_ITEM_HEIGHT = DROPDOWN_ITEM_HEIGHT + searchInputStyle.margin + searchInputStyle.marginTop;
44
44
  const defaultLabels = {
@@ -637,15 +637,30 @@ const styles$4 = StyleSheet.create({
637
637
  }
638
638
  });
639
639
 
640
- const MAX_VISIBLE_ITEMS = 9;
640
+ function getDropdownMenuHeight(items, initialHeight = 0) {
641
+ return items.slice(0, MAX_VISIBLE_ITEMS).reduce((sum, item) => {
642
+ if (SeparatorItem.isClassOf(item.component)) {
643
+ return sum + SEPARATOR_ITEM_HEIGHT;
644
+ } else if (SearchTextInput.isClassOf(item.component)) {
645
+ return sum + SEARCH_ITEM_HEIGHT;
646
+ } else {
647
+ return sum + DROPDOWN_ITEM_HEIGHT;
648
+ }
649
+ }, initialHeight);
650
+ }
651
+ function generateDropdownMenuStyles(minWidth, maxHeight) {
652
+ const styles = StyleSheet.create({
653
+ dropdownMenu: {
654
+ minWidth,
655
+ maxHeight
656
+ }
657
+ });
658
+ return styles.dropdownMenu;
659
+ }
641
660
 
642
661
  class DropdownCoreVirtualized extends React.Component {
643
- constructor(...args) {
644
- super(...args);
645
- this.state = {
646
- height: this.getHeight(),
647
- width: this.props.width
648
- };
662
+ constructor(props) {
663
+ super(props);
649
664
 
650
665
  this.getItemSize = index => {
651
666
  const item = this.props.data[index];
@@ -658,6 +673,11 @@ class DropdownCoreVirtualized extends React.Component {
658
673
  return DROPDOWN_ITEM_HEIGHT;
659
674
  }
660
675
  };
676
+
677
+ this.state = {
678
+ height: getDropdownMenuHeight(props.data),
679
+ width: props.width
680
+ };
661
681
  }
662
682
 
663
683
  componentDidMount() {
@@ -697,24 +717,12 @@ class DropdownCoreVirtualized extends React.Component {
697
717
  }
698
718
 
699
719
  setHeight() {
700
- const height = this.getHeight();
720
+ const height = getDropdownMenuHeight(this.props.data);
701
721
  this.setState({
702
722
  height
703
723
  });
704
724
  }
705
725
 
706
- getHeight() {
707
- return this.props.data.slice(0, MAX_VISIBLE_ITEMS).reduce((sum, item) => {
708
- if (SeparatorItem.isClassOf(item.component)) {
709
- return sum + SEPARATOR_ITEM_HEIGHT;
710
- } else if (SearchTextInput.isClassOf(item.component)) {
711
- return sum + SEARCH_ITEM_HEIGHT;
712
- } else {
713
- return sum + DROPDOWN_ITEM_HEIGHT;
714
- }
715
- }, 0);
716
- }
717
-
718
726
  renderInitialItems() {
719
727
  const {
720
728
  data
@@ -1273,12 +1281,12 @@ class DropdownCore extends React.Component {
1273
1281
  } = this.props;
1274
1282
  const openerStyle = openerElement && window.getComputedStyle(openerElement);
1275
1283
  const minDropdownWidth = openerStyle ? openerStyle.getPropertyValue("width") : 0;
1284
+ const initialHeight = 12;
1285
+ const maxDropdownHeight = getDropdownMenuHeight(this.props.items, initialHeight);
1276
1286
  return React.createElement(View, {
1277
1287
  onMouseUp: this.handleDropdownMouseUp,
1278
1288
  role: this.props.role,
1279
- style: [styles$3.dropdown, light && styles$3.light, isReferenceHidden && styles$3.hidden, {
1280
- minWidth: minDropdownWidth
1281
- }, dropdownStyle]
1289
+ style: [styles$3.dropdown, light && styles$3.light, isReferenceHidden && styles$3.hidden, generateDropdownMenuStyles(minDropdownWidth, maxDropdownHeight), dropdownStyle]
1282
1290
  }, listRenderer, this.maybeRenderNoResults());
1283
1291
  }
1284
1292