Skip to content

Commit dd13b00

Browse files
style(design): optimize filter style
1 parent e23471b commit dd13b00

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

packages/design/src/filter/components/FilterButton.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { ReactNode } from 'react';
22
import React, {
33
forwardRef,
44
useCallback,
5+
useEffect,
56
useImperativeHandle,
67
useMemo,
78
useRef,
@@ -77,6 +78,7 @@ const FilterButton = forwardRef<FilterButtonRef, FilterButtonProps>(
7778
const { token } = theme.useToken();
7879
const { isCollapsed } = useFilterContext();
7980
const [open, setOpen] = useState(false);
81+
const [popoverWidth, setPopoverWidth] = useState<number | undefined>();
8082
const { wrapSSR, prefixCls } = useFilterStyle();
8183
const innerRef = useRef<HTMLDivElement>(null);
8284

@@ -108,11 +110,24 @@ const FilterButton = forwardRef<FilterButtonRef, FilterButtonProps>(
108110
const handleOpenChange = (newOpen: boolean) => {
109111
if (!disabled) {
110112
setOpen(newOpen);
111-
// 调用外部传入的 onOpenChange 回调,让父组件能够实时监听状态变化
112113
externalOnOpenChange?.(newOpen);
113114
}
114115
};
115116

117+
// 折叠模式下实时监听按钮宽度变化,同步到 Popover 面板宽度
118+
useEffect(() => {
119+
if (!open || !isCollapsed || _isInWrapComponent || !innerRef.current) {
120+
return;
121+
}
122+
const el = innerRef.current;
123+
setPopoverWidth(el.offsetWidth);
124+
const observer = new ResizeObserver(() => {
125+
setPopoverWidth(el.offsetWidth);
126+
});
127+
observer.observe(el);
128+
return () => observer.disconnect();
129+
}, [open, isCollapsed, _isInWrapComponent]);
130+
116131
// 使用 useMemo 缓存 content,避免每次都重新创建
117132
const popoverContent = useMemo(
118133
() => (
@@ -171,6 +186,7 @@ const FilterButton = forwardRef<FilterButtonRef, FilterButtonProps>(
171186
padding: 0,
172187
maxWidth: 300,
173188
minWidth: 120,
189+
...(isCollapsed && !_isInWrapComponent && popoverWidth ? { width: popoverWidth } : {}),
174190
},
175191
}}
176192
{...popoverProps}

packages/design/src/filter/components/FilterCascader/components/NormalCascaderContent.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,7 @@ export const NormalCascaderContent: React.FC<NormalCascaderContentProps> = ({
127127
<div key={option.value} style={{ padding: PADDING_HORIZONTAL }}>
128128
<Flex
129129
gap={GAP_SIZE_SMALL * 2}
130-
className={classNames(getFilterCls(prefixCls, 'select-option'), {
131-
[getFilterCls(prefixCls, 'has-selected')]: isNodeSelected,
132-
})}
130+
className={getFilterCls(prefixCls, 'select-option')}
133131
justify="space-between"
134132
align="center"
135133
onClick={handleNodeClick}
@@ -229,9 +227,7 @@ export const NormalCascaderContent: React.FC<NormalCascaderContentProps> = ({
229227
<div style={{ padding: PADDING_HORIZONTAL }}>
230228
<Flex
231229
gap={GAP_SIZE_SMALL * 2}
232-
className={classNames(getFilterCls(prefixCls, 'select-option'), {
233-
[getFilterCls(prefixCls, 'has-selected')]: hasSelectedChildren,
234-
})}
230+
className={getFilterCls(prefixCls, 'select-option')}
235231
justify="space-between"
236232
align="center"
237233
style={{

packages/design/src/filter/style/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ const genFilterButtonStyle = (token: FilterToken): CSSObject => {
213213
justifyContent: 'right',
214214
color: token.colorText,
215215
whiteSpace: 'nowrap',
216-
maxWidth: '260px',
216+
maxWidth: '268px',
217217

218218
'&:hover': {
219219
[`${componentCls}-arrow-icon`]: {

0 commit comments

Comments
 (0)