@laser-ui/components 1.1.0 → 1.1.1
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 +6 -0
- package/dropdown/Dropdown.js +9 -9
- package/dropdown/internal/DropdownSub.js +2 -1
- package/internal/popup/Popup.js +1 -1
- package/internal/popup/types.d.ts +1 -0
- package/menu/Menu.js +15 -11
- package/menu/internal/MenuSub.js +2 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
## [1.1.1](https://github.com/laser-ui/laser-ui/compare/v1.1.0...v1.1.1) (2024-08-30)
|
|
6
|
+
|
|
7
|
+
### Bug Fixes
|
|
8
|
+
|
|
9
|
+
- fix automatically update when nested ([d1c0b46](https://github.com/laser-ui/laser-ui/commit/d1c0b4645965e31b382058b60b2569b253c162e5))
|
|
10
|
+
|
|
5
11
|
# [1.1.0](https://github.com/laser-ui/laser-ui/compare/v1.0.2...v1.1.0) (2024-08-30)
|
|
6
12
|
|
|
7
13
|
### Features
|
package/dropdown/Dropdown.js
CHANGED
|
@@ -9,7 +9,7 @@ import { DropdownItem as DropdownItemFC } from './internal/DropdownItem';
|
|
|
9
9
|
import { DropdownSub } from './internal/DropdownSub';
|
|
10
10
|
import { checkEnableItem, getSameLevelEnableItems } from './utils';
|
|
11
11
|
import { CLASSES } from './vars';
|
|
12
|
-
import { useComponentProps, useControlled, useFocusVisible, useJSS, useMaxIndex, useNamespace, useNestedPopup, useStyled, useTranslation, } from '../hooks';
|
|
12
|
+
import { useComponentProps, useContainerScrolling, useControlled, useFocusVisible, useJSS, useMaxIndex, useNamespace, useNestedPopup, useStyled, useTranslation, } from '../hooks';
|
|
13
13
|
import { Popup } from '../internal/popup';
|
|
14
14
|
import { Portal } from '../internal/portal';
|
|
15
15
|
import { Transition } from '../internal/transition';
|
|
@@ -254,14 +254,14 @@ function DropdownFC(props, ref) {
|
|
|
254
254
|
});
|
|
255
255
|
return getNodes(list, 0, []);
|
|
256
256
|
})();
|
|
257
|
-
|
|
258
|
-
updatePosition
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
}), [
|
|
257
|
+
const updateAllPosition = useEventCallback(() => {
|
|
258
|
+
updatePosition();
|
|
259
|
+
for (const fn of dataRef.current.updatePosition.values()) {
|
|
260
|
+
fn();
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
useContainerScrolling(triggerRef, updateAllPosition, !visible);
|
|
264
|
+
useImperativeHandle(ref, () => ({ updatePosition: updateAllPosition }), [updateAllPosition]);
|
|
265
265
|
return (_jsx(Popup, { visible: visible, trigger: trigger, updatePosition: {
|
|
266
266
|
fn: updatePosition,
|
|
267
267
|
triggerRef,
|
|
@@ -20,7 +20,7 @@ export const DropdownSub = forwardRef((props, ref) => {
|
|
|
20
20
|
const visible = !isUndefined(popupState);
|
|
21
21
|
const transformOrigin = useRef();
|
|
22
22
|
const updatePosition = useEventCallback(() => {
|
|
23
|
-
if (visible && popupRef.current && triggerRef.current) {
|
|
23
|
+
if (!disabled && visible && popupRef.current && triggerRef.current) {
|
|
24
24
|
const [width, height] = [popupRef.current.offsetWidth, popupRef.current.offsetHeight];
|
|
25
25
|
const position = getHorizontalSidePosition(triggerRef.current, { width, height }, {
|
|
26
26
|
placement: 'right',
|
|
@@ -42,6 +42,7 @@ export const DropdownSub = forwardRef((props, ref) => {
|
|
|
42
42
|
fn: updatePosition,
|
|
43
43
|
triggerRef,
|
|
44
44
|
popupRef,
|
|
45
|
+
scroll: false,
|
|
45
46
|
}, onVisibleChange: onVisibleChange, children: ({ renderTrigger, renderPopup }) => (_jsxs(_Fragment, { children: [renderTrigger(_jsxs("li", Object.assign({}, mergeCS(styled('dropdown__item', 'dropdown__item--sub', {
|
|
46
47
|
'dropdown__item.is-expand': visible,
|
|
47
48
|
'dropdown__item.is-disabled': disabled,
|
package/internal/popup/Popup.js
CHANGED
|
@@ -42,7 +42,7 @@ export function Popup(props) {
|
|
|
42
42
|
changeVisible();
|
|
43
43
|
}
|
|
44
44
|
};
|
|
45
|
-
useContainerScrolling(updatePosition.triggerRef, updatePosition.fn, disabled || !visibleProp);
|
|
45
|
+
useContainerScrolling(updatePosition.triggerRef, updatePosition.fn, disabled || updatePosition.scroll === false || !visibleProp);
|
|
46
46
|
useResize(updatePosition.triggerRef, updatePosition.fn, undefined, disabled || !visibleProp);
|
|
47
47
|
useResize(updatePosition.popupRef, updatePosition.fn, undefined, disabled || !visibleProp);
|
|
48
48
|
useResize(contentResizeRef, updatePosition.fn, undefined, disabled || !visibleProp);
|
package/menu/Menu.js
CHANGED
|
@@ -2,13 +2,13 @@ import { __rest } from "tslib";
|
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import { findNested } from '@laser-ui/utils';
|
|
4
4
|
import { isNull, isUndefined, nth } from 'lodash';
|
|
5
|
-
import { Fragment, forwardRef, useId, useImperativeHandle, useRef, useState } from 'react';
|
|
5
|
+
import { Fragment, forwardRef, useCallback, useId, useImperativeHandle, useRef, useState } from 'react';
|
|
6
6
|
import { MenuGroup } from './internal/MenuGroup';
|
|
7
7
|
import { MenuItem as MenuItemFC } from './internal/MenuItem';
|
|
8
8
|
import { MenuSub } from './internal/MenuSub';
|
|
9
9
|
import { checkEnableItem, getSameLevelEnableItems } from './utils';
|
|
10
10
|
import { CLASSES } from './vars';
|
|
11
|
-
import { useComponentProps, useControlled, useFocusVisible, useNamespace, useNestedPopup, useStyled } from '../hooks';
|
|
11
|
+
import { useComponentProps, useContainerScrolling, useControlled, useFocusVisible, useNamespace, useNestedPopup, useStyled, } from '../hooks';
|
|
12
12
|
import { CollapseTransition } from '../internal/transition';
|
|
13
13
|
import { mergeCS } from '../utils';
|
|
14
14
|
import { TTANSITION_DURING_BASE } from '../vars';
|
|
@@ -18,6 +18,7 @@ function MenuFC(props, ref) {
|
|
|
18
18
|
const styled = useStyled(CLASSES, { menu: styleProvider === null || styleProvider === void 0 ? void 0 : styleProvider.menu, 'menu-popup': styleProvider === null || styleProvider === void 0 ? void 0 : styleProvider['menu-popup'] }, styleOverrides);
|
|
19
19
|
const uniqueId = useId();
|
|
20
20
|
const getItemId = (id) => `${namespace}-menu-item-${id}-${uniqueId}`;
|
|
21
|
+
const menuRef = useRef(null);
|
|
21
22
|
const dataRef = useRef({
|
|
22
23
|
mousedown: false,
|
|
23
24
|
updatePosition: new Map(),
|
|
@@ -324,13 +325,13 @@ function MenuFC(props, ref) {
|
|
|
324
325
|
};
|
|
325
326
|
return getNodes(list, 0, [], true);
|
|
326
327
|
})();
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
}), []);
|
|
328
|
+
const updatePosition = useCallback(() => {
|
|
329
|
+
for (const fn of dataRef.current.updatePosition.values()) {
|
|
330
|
+
fn();
|
|
331
|
+
}
|
|
332
|
+
}, []);
|
|
333
|
+
useContainerScrolling(menuRef, updatePosition);
|
|
334
|
+
useImperativeHandle(ref, () => ({ updatePosition }), [updatePosition]);
|
|
334
335
|
return (_jsx(CollapseTransition, { originalSize: {
|
|
335
336
|
width,
|
|
336
337
|
}, collapsedSize: {
|
|
@@ -342,7 +343,7 @@ function MenuFC(props, ref) {
|
|
|
342
343
|
leaving: {
|
|
343
344
|
transition: ['width', 'padding', 'margin'].map((attr) => `${attr} ${TTANSITION_DURING_BASE}ms linear`).join(', '),
|
|
344
345
|
},
|
|
345
|
-
}, children: (
|
|
346
|
+
}, children: (collapseRef, collapseStyle) => {
|
|
346
347
|
var _a;
|
|
347
348
|
const preventBlur = (e) => {
|
|
348
349
|
if (document.activeElement === e.currentTarget && e.button === 0) {
|
|
@@ -354,7 +355,10 @@ function MenuFC(props, ref) {
|
|
|
354
355
|
_jsx("nav", Object.assign({}, restProps, mergeCS(styled('menu', { 'menu--horizontal': mode === 'horizontal' }), {
|
|
355
356
|
className: restProps.className,
|
|
356
357
|
style: Object.assign(Object.assign(Object.assign({}, restProps.style), { width }), collapseStyle),
|
|
357
|
-
}), { ref:
|
|
358
|
+
}), { ref: (el) => {
|
|
359
|
+
collapseRef.current = el;
|
|
360
|
+
menuRef.current = el;
|
|
361
|
+
}, tabIndex: (_a = restProps.tabIndex) !== null && _a !== void 0 ? _a : 0, role: "menubar", "aria-orientation": mode === 'horizontal' ? 'horizontal' : 'vertical', "aria-activedescendant": isUndefined(focusId) ? undefined : getItemId(focusId), onFocus: (e) => {
|
|
358
362
|
var _a;
|
|
359
363
|
(_a = restProps.onFocus) === null || _a === void 0 ? void 0 : _a.call(restProps, e);
|
|
360
364
|
if (!dataRef.current.mousedown) {
|
package/menu/internal/MenuSub.js
CHANGED
|
@@ -21,7 +21,7 @@ export const MenuSub = forwardRef((props, ref) => {
|
|
|
21
21
|
const iconMode = mode === 'icon' && inNav;
|
|
22
22
|
const transformOrigin = useRef();
|
|
23
23
|
const updatePosition = useEventCallback(() => {
|
|
24
|
-
if (visible && popupRef.current && triggerRef.current) {
|
|
24
|
+
if (!(disabled || mode === 'vertical') && visible && popupRef.current && triggerRef.current) {
|
|
25
25
|
const height = popupRef.current.offsetHeight;
|
|
26
26
|
let width = popupRef.current.offsetWidth;
|
|
27
27
|
if (inHorizontalNav) {
|
|
@@ -56,6 +56,7 @@ export const MenuSub = forwardRef((props, ref) => {
|
|
|
56
56
|
fn: updatePosition,
|
|
57
57
|
triggerRef,
|
|
58
58
|
popupRef,
|
|
59
|
+
scroll: false,
|
|
59
60
|
}, onVisibleChange: onVisibleChange, children: ({ renderTrigger, renderPopup }) => (_jsxs(_Fragment, { children: [renderTrigger(_jsxs("li", Object.assign({}, mergeCS(styled('menu__item', 'menu__item--sub', {
|
|
60
61
|
'menu__item--horizontal': inHorizontalNav,
|
|
61
62
|
'menu__item--icon': iconMode,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@laser-ui/components",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "React components.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ui",
|
|
@@ -40,5 +40,5 @@
|
|
|
40
40
|
"access": "public",
|
|
41
41
|
"directory": "../../dist/libs/components"
|
|
42
42
|
},
|
|
43
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "5d76520ca057de8e9b23faa06ad88d5e7429d64d"
|
|
44
44
|
}
|