nitro-web 0.2.2 → 0.2.3
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.
|
@@ -72,7 +72,9 @@ export const Dropdown = forwardRef(function Dropdown({
|
|
|
72
72
|
const pageClick = (event: MouseEvent | FocusEvent) => {
|
|
73
73
|
try {
|
|
74
74
|
// If the active element exists and is clicked outside of the dropdown, toggle the dropdown
|
|
75
|
-
if (dropdownRef.current !== null && !dropdownRef.current.contains(event.target as Node))
|
|
75
|
+
if (dropdownRef.current !== null && !dropdownRef.current.contains(event.target as Node)) {
|
|
76
|
+
setIsActive(!isActive)
|
|
77
|
+
}
|
|
76
78
|
} catch (_e) {
|
|
77
79
|
// Errors throw for contains() when the user clicks off the webpage when open
|
|
78
80
|
setIsActive(!isActive)
|
|
@@ -148,7 +150,7 @@ export const Dropdown = forwardRef(function Dropdown({
|
|
|
148
150
|
}
|
|
149
151
|
}
|
|
150
152
|
|
|
151
|
-
function
|
|
153
|
+
function onItemClick(option: { onClick?: Function, preventCloseOnClick?: boolean }, e: React.MouseEvent) {
|
|
152
154
|
if (option.onClick) option.onClick(e, option)
|
|
153
155
|
if (!menuIsOpen && !option?.preventCloseOnClick) setIsActive(!isActive)
|
|
154
156
|
}
|
|
@@ -164,7 +166,10 @@ export const Dropdown = forwardRef(function Dropdown({
|
|
|
164
166
|
' nitro-dropdown' +
|
|
165
167
|
(className ? ` ${className}` : '')
|
|
166
168
|
}
|
|
167
|
-
|
|
169
|
+
// When the dropdown is inside a link, prevent click propagation
|
|
170
|
+
onClick={(e) => { e.preventDefault() }}
|
|
171
|
+
// When the dropdown is inside a link, prevent auto <a> focus propagation (for the window listener)
|
|
172
|
+
onMouseDown={(e) => { e.preventDefault() }}
|
|
168
173
|
ref={dropdownRef}
|
|
169
174
|
css={style}
|
|
170
175
|
>
|
|
@@ -192,7 +197,7 @@ export const Dropdown = forwardRef(function Dropdown({
|
|
|
192
197
|
<li
|
|
193
198
|
key={i}
|
|
194
199
|
className={twMerge(`${optionStyle} ${option.className} ${menuOptionClassName}`)}
|
|
195
|
-
onClick={(e: React.MouseEvent) =>
|
|
200
|
+
onClick={(e: React.MouseEvent) => onItemClick(option, e)}
|
|
196
201
|
>
|
|
197
202
|
{ !!option.iconLeft && option.iconLeft }
|
|
198
203
|
<span class="flex-auto">{option.label}</span>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nitro-web",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"repository": "github:boycce/nitro-web",
|
|
5
5
|
"homepage": "https://boycce.github.io/nitro-web/",
|
|
6
6
|
"description": "Nitro is a battle-tested, modular base project to turbocharge your projects, styled using Tailwind 🚀",
|