@pushwoosh/dumb-components 2.9.9 → 2.9.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pushwoosh/dumb-components",
3
- "version": "2.9.9",
3
+ "version": "2.9.10",
4
4
  "description": "React components to build Pushwoosh products",
5
5
  "main": "index.js",
6
6
  "module": "index.js",
@@ -0,0 +1,60 @@
1
+ import { renderHook } from '@testing-library/react';
2
+ import { useDropdownPosition } from '../useDropdownPosition';
3
+ const floating = {
4
+ middleware: []
5
+ };
6
+ jest.mock('@floating-ui/react-dom', () => ({
7
+ ...jest.requireActual('@floating-ui/react-dom'),
8
+ size: options => ({
9
+ name: 'size',
10
+ options
11
+ }),
12
+ useFloating: config => {
13
+ floating.middleware = config.middleware;
14
+ return {
15
+ refs: {
16
+ reference: {
17
+ current: null
18
+ },
19
+ floating: {
20
+ current: null
21
+ },
22
+ setReference: jest.fn(),
23
+ setFloating: jest.fn()
24
+ },
25
+ floatingStyles: {}
26
+ };
27
+ }
28
+ }));
29
+ const maxHeightFor = availableHeight => {
30
+ renderHook(() => useDropdownPosition({
31
+ isOpen: true
32
+ }));
33
+ const style = {};
34
+ floating.middleware.find(m => m.name === 'size').options.apply({
35
+ rects: {
36
+ reference: {
37
+ width: 200
38
+ }
39
+ },
40
+ elements: {
41
+ floating: {
42
+ style
43
+ }
44
+ },
45
+ availableWidth: 1000,
46
+ availableHeight
47
+ });
48
+ return style.maxHeight;
49
+ };
50
+ describe('useDropdownPosition max height', () => {
51
+ it('caps the dropdown at 300px when there is more room', () => {
52
+ expect(maxHeightFor(1200)).toBe('300px');
53
+ });
54
+ it('shrinks to the room below the field when it is less than the cap', () => {
55
+ expect(maxHeightFor(200)).toBe('192px');
56
+ });
57
+ it('never goes negative', () => {
58
+ expect(maxHeightFor(4)).toBe('0px');
59
+ });
60
+ });
@@ -1,7 +1,7 @@
1
1
  import { Color } from '@pushwoosh/kit-constants';
2
2
  export declare const LOADING_BORDER_COLORS: readonly [Color.PRIMARY, Color.BRIGHT, Color.BRAND_GREEN, Color.EXCEPTIONAL];
3
3
  export declare const LOADING_BORDER_ANIMATION_MS = 3000;
4
- export declare const DROPDOWN_MAX_HEIGHT = 280;
4
+ export declare const DROPDOWN_MAX_HEIGHT = 300;
5
5
  /** Default dropdown width cap. A field wider than this stretches the dropdown to its own width only when the field opts in via `fullWidth`; otherwise the dropdown stays capped here. */
6
6
  export declare const DROPDOWN_DEFAULT_WIDTH = 320;
7
7
  /** Default debounce (ms) before an async `loadItems` call fires after the query changes. */
@@ -1,7 +1,7 @@
1
1
  import { Color } from '@pushwoosh/kit-constants';
2
2
  export const LOADING_BORDER_COLORS = [Color.PRIMARY, Color.BRIGHT, Color.BRAND_GREEN, Color.EXCEPTIONAL];
3
3
  export const LOADING_BORDER_ANIMATION_MS = 3000;
4
- export const DROPDOWN_MAX_HEIGHT = 280;
4
+ export const DROPDOWN_MAX_HEIGHT = 300;
5
5
  /** Default dropdown width cap. A field wider than this stretches the dropdown to its own width only when the field opts in via `fullWidth`; otherwise the dropdown stays capped here. */
6
6
  export const DROPDOWN_DEFAULT_WIDTH = 320;
7
7
  /** Default debounce (ms) before an async `loadItems` call fires after the query changes. */
@@ -1,5 +1,5 @@
1
1
  import { autoUpdate, flip, offset, size, useFloating } from '@floating-ui/react-dom';
2
- import { DROPDOWN_DEFAULT_WIDTH } from './constants';
2
+ import { DROPDOWN_DEFAULT_WIDTH, DROPDOWN_MAX_HEIGHT } from './constants';
3
3
  import { useOnClickOutside } from '../../hooks';
4
4
  /**
5
5
  * Positions the dropdown relative to the field via floating-ui (flip, offset,
@@ -32,7 +32,7 @@ export function useDropdownPosition({
32
32
  Object.assign(elements.floating.style, {
33
33
  minWidth: `${minWidth}px`,
34
34
  maxWidth: `${maxWidth}px`,
35
- maxHeight: `${Math.max(0, availableHeight - 8)}px`
35
+ maxHeight: `${Math.max(0, Math.min(DROPDOWN_MAX_HEIGHT, availableHeight - 8))}px`
36
36
  });
37
37
  }
38
38
  })],