@decisiv/ui-components 2.0.1-alpha.196 → 2.0.1-alpha.198
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/lib/components/Combobox/index.d.ts.map +1 -1
- package/lib/components/Combobox/index.js +26 -24
- package/lib/components/Combobox/index.test.js +3 -3
- package/lib/components/Drawer/index.d.ts +1 -1
- package/lib/components/Drawer/index.d.ts.map +1 -1
- package/lib/components/Drawer/index.js +12 -2
- package/lib/components/Drawer/index.test.js +17 -0
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/Combobox/index.tsx"],"names":[],"mappings":"AASA,OAAc,EAGZ,sBAAsB,EAQvB,MAAM,OAAO,CAAC;AA2Bf,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAQ,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/Combobox/index.tsx"],"names":[],"mappings":"AASA,OAAc,EAGZ,sBAAsB,EAQvB,MAAM,OAAO,CAAC;AA2Bf,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAQ,MAAM,SAAS,CAAC;AAmjBhE,QAAA,MAAM,eAAe,EAAE,sBAAsB,CAC3C,gBAAgB,EAChB,aAAa,CACS,CAAC;AAOzB,eAAe,eAAe,CAAC"}
|
|
@@ -337,45 +337,41 @@ function Combobox(props, ref) {
|
|
|
337
337
|
* Usually that's fine. In this case, we don't want that behavior.
|
|
338
338
|
*/
|
|
339
339
|
updateIsPopoverVisible(false);
|
|
340
|
-
} else if (
|
|
341
|
-
|
|
342
|
-
|
|
340
|
+
} else if (variant === 'sync' && finalComboboxRef && // @ts-ignore
|
|
341
|
+
finalComboboxRef.current === event.target) {
|
|
342
|
+
/**
|
|
343
|
+
* This prevents a double toggle when the user clicks
|
|
344
|
+
* the actual input field inside the combobox.
|
|
345
|
+
*/
|
|
346
|
+
event.preventDefault();
|
|
347
|
+
event.stopPropagation();
|
|
348
|
+
|
|
349
|
+
if (!isPopoverVisible) {
|
|
343
350
|
/**
|
|
344
|
-
* This
|
|
345
|
-
*
|
|
351
|
+
* This re-opens the popover if you first open it,
|
|
352
|
+
* then make a selection, then click the <input> again.
|
|
346
353
|
*/
|
|
347
|
-
|
|
348
|
-
event.stopPropagation();
|
|
349
|
-
|
|
350
|
-
if (!isPopoverVisible) {
|
|
351
|
-
/**
|
|
352
|
-
* This re-opens the popover if you first open it,
|
|
353
|
-
* then make a selection, then click the <input> again.
|
|
354
|
-
*/
|
|
355
|
-
updateIsPopoverVisible(true);
|
|
356
|
-
}
|
|
357
|
-
} else {
|
|
358
|
-
updateIsPopoverVisible('toggle');
|
|
354
|
+
updateIsPopoverVisible(true);
|
|
359
355
|
}
|
|
356
|
+
} else {
|
|
357
|
+
updateIsPopoverVisible('toggle');
|
|
360
358
|
}
|
|
361
359
|
|
|
362
360
|
onClick && onClick(event);
|
|
363
|
-
},
|
|
364
|
-
[isFocused, isPopoverVisible, variant, onClick, updateIsPopoverVisible]);
|
|
361
|
+
}, [finalInputContainerRef, onClick, updateIsPopoverVisible, variant, finalComboboxRef, isPopoverVisible]);
|
|
365
362
|
/**
|
|
366
363
|
* This focus handler is responsible for opening the dropdown list and tracking focus state.
|
|
367
364
|
* It's important to do this in the focus handler because the dropdown should open when the
|
|
368
365
|
* Combobox is clicked or tabbed to.
|
|
366
|
+
*
|
|
367
|
+
* [KDS-3742] Patch: Updated this handler to align the behavior with the Select component.
|
|
368
|
+
* The popover will no longer automatically show when the Combobox gains focus.
|
|
369
369
|
*/
|
|
370
370
|
|
|
371
371
|
var handleContainerFocus = (0, _react.useCallback)(function (event) {
|
|
372
|
-
if (variant === 'sync') {
|
|
373
|
-
updateIsPopoverVisible(true);
|
|
374
|
-
}
|
|
375
|
-
|
|
376
372
|
setIsFocused(true);
|
|
377
373
|
onFocus && onFocus(event);
|
|
378
|
-
}, [onFocus
|
|
374
|
+
}, [onFocus]);
|
|
379
375
|
/**
|
|
380
376
|
* Pressing certain keys when focused on the Combobox component should trigger some actions.
|
|
381
377
|
*/
|
|
@@ -410,7 +406,13 @@ function Combobox(props, ref) {
|
|
|
410
406
|
}
|
|
411
407
|
}
|
|
412
408
|
|
|
409
|
+
if (event.key === 'Enter' && !isPopoverVisible) {
|
|
410
|
+
event.preventDefault();
|
|
411
|
+
updateIsPopoverVisible(true);
|
|
412
|
+
}
|
|
413
|
+
|
|
413
414
|
if (event.key === 'Enter' && isPopoverVisible) {
|
|
415
|
+
event.preventDefault();
|
|
414
416
|
updateSelected(activeId || '');
|
|
415
417
|
updateIsPopoverVisible(false);
|
|
416
418
|
}
|
|
@@ -110,7 +110,7 @@ describe('Combobox', function () {
|
|
|
110
110
|
expect(getByLabelText('test')).toBeVisible();
|
|
111
111
|
});
|
|
112
112
|
});
|
|
113
|
-
describe('when the input field
|
|
113
|
+
describe('when the input field is clicked', function () {
|
|
114
114
|
it('displays the list of options', function () {
|
|
115
115
|
var _render4 = render(_react.default.createElement(_.default, {
|
|
116
116
|
label: "test",
|
|
@@ -958,7 +958,7 @@ describe('Combobox', function () {
|
|
|
958
958
|
});
|
|
959
959
|
describe('when a controlled component', function () {
|
|
960
960
|
it('initializes with and prefers prop values', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
|
|
961
|
-
var newInputValue, onChangeInputValue, onChangeValue, _render32, baseElement, queryByLabelText, rerender
|
|
961
|
+
var newInputValue, onChangeInputValue, onChangeValue, _render32, baseElement, queryByLabelText, rerender;
|
|
962
962
|
|
|
963
963
|
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
964
964
|
while (1) {
|
|
@@ -977,7 +977,7 @@ describe('Combobox', function () {
|
|
|
977
977
|
onChangeValue: onChangeValue,
|
|
978
978
|
autoComplete: "auto-complete-test",
|
|
979
979
|
type: "search"
|
|
980
|
-
})), baseElement = _render32.baseElement, queryByLabelText = _render32.queryByLabelText, rerender = _render32.rerender
|
|
980
|
+
})), baseElement = _render32.baseElement, queryByLabelText = _render32.queryByLabelText, rerender = _render32.rerender;
|
|
981
981
|
|
|
982
982
|
_react2.fireEvent.click(queryByLabelText('test'));
|
|
983
983
|
|
|
@@ -14,7 +14,7 @@ export interface DrawerProps extends HeaderProps, FooterProps {
|
|
|
14
14
|
side?: 'left' | 'right';
|
|
15
15
|
zIndex?: number;
|
|
16
16
|
visible?: boolean;
|
|
17
|
-
onClose?: (event:
|
|
17
|
+
onClose?: (event: MouseEvent | KeyboardEvent) => void;
|
|
18
18
|
}
|
|
19
19
|
export declare type OverlayProps = Pick<DrawerProps, 'zIndex' | 'side' | 'visible'>;
|
|
20
20
|
declare const Drawer: React.FC<DrawerProps>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/Drawer/index.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/Drawer/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAyC,MAAM,OAAO,CAAC;AAI9D,OAAe,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAmBhD,UAAU,WAAW;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,UAAU,MAAO,SAAQ,WAAW;IAClC,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,UAAU,WAAW;IACnB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,MAAM,WAAW,WAAY,SAAQ,WAAW,EAAE,WAAW;IAC3D,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,GAAG,aAAa,KAAK,IAAI,CAAC;CACvD;AAED,oBAAY,YAAY,GAAG,IAAI,CAAC,WAAW,EAAE,QAAQ,GAAG,MAAM,GAAG,SAAS,CAAC,CAAC;AAE5E,QAAA,MAAM,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC,WAAW,CAmHjC,CAAC;AAEF,eAAe,MAAM,CAAC"}
|
|
@@ -25,6 +25,8 @@ var _styles = require("./styles");
|
|
|
25
25
|
|
|
26
26
|
var _useTranslations = _interopRequireDefault(require("../../utils/useTranslations"));
|
|
27
27
|
|
|
28
|
+
var _useClickOutside = _interopRequireDefault(require("../../utils/useClickOutside"));
|
|
29
|
+
|
|
28
30
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
29
31
|
|
|
30
32
|
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
|
|
@@ -47,11 +49,18 @@ var Drawer = function Drawer(_ref) {
|
|
|
47
49
|
createPortal = _useConfig.createPortal;
|
|
48
50
|
|
|
49
51
|
var translate = (0, _useTranslations.default)();
|
|
52
|
+
var contentRef = (0, _react.useRef)(null);
|
|
50
53
|
var onKeyDown = (0, _react.useCallback)(function (event) {
|
|
51
54
|
if (event.key === 'Escape') {
|
|
52
55
|
onClose && onClose(event);
|
|
53
56
|
}
|
|
54
|
-
}, [onClose]);
|
|
57
|
+
}, [onClose]);
|
|
58
|
+
var handleOnClickOutside = (0, _react.useCallback)(function (event) {
|
|
59
|
+
if (onClose && visible) {
|
|
60
|
+
onClose(event);
|
|
61
|
+
}
|
|
62
|
+
}, [onClose, visible]);
|
|
63
|
+
(0, _useClickOutside.default)([contentRef], handleOnClickOutside); // Allow closing the modal by pressing the Escape key
|
|
55
64
|
|
|
56
65
|
(0, _react.useEffect)(function () {
|
|
57
66
|
if (visible && _canUseDOM.default) {
|
|
@@ -74,8 +83,9 @@ var Drawer = function Drawer(_ref) {
|
|
|
74
83
|
visible: visible,
|
|
75
84
|
"data-testid": "overlay"
|
|
76
85
|
}, _react.default.createElement(_styles.Content, {
|
|
77
|
-
|
|
86
|
+
ref: contentRef,
|
|
78
87
|
side: side,
|
|
88
|
+
visible: visible,
|
|
79
89
|
"data-testid": "content"
|
|
80
90
|
}, showHeader && _react.default.createElement(_styles.Header, {
|
|
81
91
|
"data-testid": "drawer-header"
|
|
@@ -119,4 +119,21 @@ describe('Drawer', function () {
|
|
|
119
119
|
});
|
|
120
120
|
});
|
|
121
121
|
});
|
|
122
|
+
describe('click outside', function () {
|
|
123
|
+
it('calls the "onClose" function when clicking outside the Drawer', function () {
|
|
124
|
+
var onClose = jest.fn();
|
|
125
|
+
|
|
126
|
+
var _render7 = render(_react.default.createElement(_.default, {
|
|
127
|
+
visible: true,
|
|
128
|
+
onClose: onClose
|
|
129
|
+
})),
|
|
130
|
+
getByTestId = _render7.getByTestId;
|
|
131
|
+
|
|
132
|
+
var overlay = getByTestId(/overlay/i);
|
|
133
|
+
|
|
134
|
+
_react2.fireEvent.click(overlay);
|
|
135
|
+
|
|
136
|
+
expect(onClose).toHaveBeenCalled();
|
|
137
|
+
});
|
|
138
|
+
});
|
|
122
139
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@decisiv/ui-components",
|
|
3
|
-
"version": "2.0.1-alpha.
|
|
3
|
+
"version": "2.0.1-alpha.198+f78212f",
|
|
4
4
|
"description": "Decisiv's design system React components",
|
|
5
5
|
"author": "Decisiv UI Development Team",
|
|
6
6
|
"license": "MIT",
|
|
@@ -71,5 +71,5 @@
|
|
|
71
71
|
"access": "public"
|
|
72
72
|
},
|
|
73
73
|
"private": false,
|
|
74
|
-
"gitHead": "
|
|
74
|
+
"gitHead": "f78212fe48488d8667830efc7e5dedeb8fe6a5ce"
|
|
75
75
|
}
|