@faststore/ui 1.6.23 → 1.6.26
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 +30 -0
- package/dist/molecules/Dropdown/DropdownMenu.d.ts +2 -2
- package/dist/ui.cjs.development.js +46 -22
- package/dist/ui.cjs.development.js.map +1 -1
- package/dist/ui.cjs.production.min.js +1 -1
- package/dist/ui.cjs.production.min.js.map +1 -1
- package/dist/ui.esm.js +46 -22
- package/dist/ui.esm.js.map +1 -1
- package/package.json +3 -3
- package/src/molecules/Dropdown/Dropdown.test.tsx +119 -8
- package/src/molecules/Dropdown/Dropdown.tsx +44 -7
- package/src/molecules/Dropdown/DropdownMenu.tsx +8 -20
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,36 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## 1.6.26 (2022-03-31)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **api:** Handle channel as facet for search and product queries ([#1197](https://github.com/vtex/faststore/issues/1197)) ([00556b1](https://github.com/vtex/faststore/commit/00556b199a48617ff89b1a6b951a0c958f5aa018))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## 1.6.25 (2022-03-29)
|
|
18
|
+
|
|
19
|
+
**Note:** Version bump only for package @faststore/ui
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
## 1.6.24 (2022-03-29)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
### Bug Fixes
|
|
29
|
+
|
|
30
|
+
* fix dropdown click bug ([#1196](https://github.com/vtex/faststore/issues/1196)) ([55202ea](https://github.com/vtex/faststore/commit/55202ead64933b71688ac7399211cc2f086596f2))
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
6
36
|
## 1.6.23 (2022-03-28)
|
|
7
37
|
|
|
8
38
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AriaAttributes, KeyboardEvent,
|
|
1
|
+
import type { AriaAttributes, KeyboardEvent, PropsWithChildren, MouseEvent, ReactNode } from 'react';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import type { ModalContentProps } from '../Modal/ModalContent';
|
|
4
4
|
export interface DropdownMenuProps extends ModalContentProps {
|
|
@@ -16,7 +16,7 @@ export interface DropdownMenuProps extends ModalContentProps {
|
|
|
16
16
|
* the dialog.
|
|
17
17
|
*/
|
|
18
18
|
onDismiss?: (event: MouseEvent | KeyboardEvent) => void;
|
|
19
|
-
children:
|
|
19
|
+
children: ReactNode[] | ReactNode;
|
|
20
20
|
}
|
|
21
21
|
declare const DropdownMenu: ({ children, testId, style, ...otherProps }: PropsWithChildren<DropdownMenuProps>) => React.ReactPortal | null;
|
|
22
22
|
export default DropdownMenu;
|
|
@@ -1577,19 +1577,30 @@ const Dropdown = ({
|
|
|
1577
1577
|
const dropdownItemsRef = React.useRef([]);
|
|
1578
1578
|
const selectedDropdownItemIndexRef = React.useRef(0);
|
|
1579
1579
|
const dropdownButtonRef = React.useRef(null);
|
|
1580
|
+
const close = React.useCallback(() => {
|
|
1581
|
+
var _dropdownButtonRef$cu;
|
|
1580
1582
|
|
|
1581
|
-
const close = () => {
|
|
1582
1583
|
setIsOpen(false);
|
|
1583
|
-
|
|
1584
|
+
onDismiss == null ? void 0 : onDismiss();
|
|
1585
|
+
(_dropdownButtonRef$cu = dropdownButtonRef.current) == null ? void 0 : _dropdownButtonRef$cu.focus();
|
|
1586
|
+
}, [onDismiss]);
|
|
1584
1587
|
|
|
1585
1588
|
const open = () => {
|
|
1586
1589
|
setIsOpen(true);
|
|
1587
1590
|
};
|
|
1588
1591
|
|
|
1589
|
-
const toggle = () => {
|
|
1590
|
-
setIsOpen(old =>
|
|
1591
|
-
|
|
1592
|
+
const toggle = React.useCallback(() => {
|
|
1593
|
+
setIsOpen(old => {
|
|
1594
|
+
if (old) {
|
|
1595
|
+
var _dropdownButtonRef$cu2;
|
|
1596
|
+
|
|
1597
|
+
onDismiss == null ? void 0 : onDismiss();
|
|
1598
|
+
(_dropdownButtonRef$cu2 = dropdownButtonRef.current) == null ? void 0 : _dropdownButtonRef$cu2.focus();
|
|
1599
|
+
}
|
|
1592
1600
|
|
|
1601
|
+
return !old;
|
|
1602
|
+
});
|
|
1603
|
+
}, [onDismiss]);
|
|
1593
1604
|
React.useEffect(() => {
|
|
1594
1605
|
setIsOpen(isOpenDefault);
|
|
1595
1606
|
}, [isOpenDefault]);
|
|
@@ -1598,6 +1609,30 @@ const Dropdown = ({
|
|
|
1598
1609
|
|
|
1599
1610
|
isOpen && (dropdownItemsRef == null ? void 0 : (_dropdownItemsRef$cur = dropdownItemsRef.current[0]) == null ? void 0 : _dropdownItemsRef$cur.focus());
|
|
1600
1611
|
}, [isOpen]);
|
|
1612
|
+
React.useEffect(() => {
|
|
1613
|
+
let firstClick = true;
|
|
1614
|
+
|
|
1615
|
+
const event = e => {
|
|
1616
|
+
const someItemWasClicked = dropdownItemsRef == null ? void 0 : dropdownItemsRef.current.some(item => e.target === item);
|
|
1617
|
+
|
|
1618
|
+
if (firstClick) {
|
|
1619
|
+
firstClick = false;
|
|
1620
|
+
return;
|
|
1621
|
+
}
|
|
1622
|
+
|
|
1623
|
+
!someItemWasClicked && close();
|
|
1624
|
+
};
|
|
1625
|
+
|
|
1626
|
+
if (isOpen) {
|
|
1627
|
+
document.addEventListener('click', event);
|
|
1628
|
+
} else {
|
|
1629
|
+
document.removeEventListener('click', event);
|
|
1630
|
+
}
|
|
1631
|
+
|
|
1632
|
+
return () => {
|
|
1633
|
+
document.removeEventListener('click', event);
|
|
1634
|
+
};
|
|
1635
|
+
}, [close, isOpen]);
|
|
1601
1636
|
const value = React.useMemo(() => {
|
|
1602
1637
|
return {
|
|
1603
1638
|
isOpen,
|
|
@@ -1610,7 +1645,7 @@ const Dropdown = ({
|
|
|
1610
1645
|
dropdownItemsRef,
|
|
1611
1646
|
id
|
|
1612
1647
|
};
|
|
1613
|
-
}, [id, isOpen, onDismiss]);
|
|
1648
|
+
}, [close, id, isOpen, onDismiss, toggle]);
|
|
1614
1649
|
return React__default.createElement(DropdownContext.Provider, {
|
|
1615
1650
|
value: value
|
|
1616
1651
|
}, children);
|
|
@@ -1743,23 +1778,12 @@ const DropdownMenu = ({
|
|
|
1743
1778
|
const {
|
|
1744
1779
|
isOpen,
|
|
1745
1780
|
close,
|
|
1746
|
-
onDismiss,
|
|
1747
1781
|
dropdownItemsRef,
|
|
1748
1782
|
selectedDropdownItemIndexRef,
|
|
1749
1783
|
id
|
|
1750
1784
|
} = useDropdown();
|
|
1751
1785
|
const dropdownPosition = useDropdownPosition();
|
|
1752
|
-
const childrenLength = children.length;
|
|
1753
|
-
|
|
1754
|
-
const handleBackdropClick = event => {
|
|
1755
|
-
if (event.defaultPrevented) {
|
|
1756
|
-
return;
|
|
1757
|
-
}
|
|
1758
|
-
|
|
1759
|
-
event.stopPropagation();
|
|
1760
|
-
onDismiss == null ? void 0 : onDismiss();
|
|
1761
|
-
close == null ? void 0 : close();
|
|
1762
|
-
};
|
|
1786
|
+
const childrenLength = React__default.Children.toArray(children).length;
|
|
1763
1787
|
|
|
1764
1788
|
const handleDownPress = () => {
|
|
1765
1789
|
var _dropdownItemsRef$cur;
|
|
@@ -1800,7 +1824,6 @@ const DropdownMenu = ({
|
|
|
1800
1824
|
};
|
|
1801
1825
|
|
|
1802
1826
|
const handleEscapePress = () => {
|
|
1803
|
-
onDismiss == null ? void 0 : onDismiss();
|
|
1804
1827
|
close == null ? void 0 : close();
|
|
1805
1828
|
};
|
|
1806
1829
|
|
|
@@ -1823,10 +1846,11 @@ const DropdownMenu = ({
|
|
|
1823
1846
|
return null;
|
|
1824
1847
|
};
|
|
1825
1848
|
|
|
1826
|
-
return isOpen ? reactDom.createPortal(React__default.createElement(
|
|
1849
|
+
return isOpen ? reactDom.createPortal(React__default.createElement("div", {
|
|
1850
|
+
role: "presentation",
|
|
1827
1851
|
"data-store-dropdown-overlay": true,
|
|
1828
|
-
|
|
1829
|
-
|
|
1852
|
+
onKeyDown: handleBackdropKeyDown,
|
|
1853
|
+
"data-testid": `${testId}-overlay`
|
|
1830
1854
|
}, React__default.createElement("div", Object.assign({
|
|
1831
1855
|
role: "menu",
|
|
1832
1856
|
"aria-orientation": "vertical",
|