((prop
}
}
+ // 搜索框
+ const searchInput = isSearchable ? (
+
+ {
+ const value = e.target.value;
+ setSearchValueFn(value);
+ onSearch?.(value);
+ }}
+ onKeyDown={e => {
+ if (e.key === 'ArrowDown') {
+ e.preventDefault();
+ selectOffset(1);
+ } else if (e.key === 'ArrowUp') {
+ e.preventDefault();
+ selectOffset(-1);
+ } else if (e.key === 'Enter' && selectedKey) {
+ e.preventDefault();
+ onTabClick(selectedKey, e);
+ setOpen(false);
+ }
+ }}
+ onClick={e => e.stopPropagation()}
+ />
+
+ ) : null;
+
// ========================= Effect =========================
useEffect(() => {
// We use query element here to avoid React strict warning
const ele = document.getElementById(selectedItemId);
if (ele?.scrollIntoView) {
- ele.scrollIntoView(false);
+ ele.scrollIntoView({ block: 'center', behavior: 'smooth' });
}
}, [selectedItemId, selectedKey]);
useEffect(() => {
- if (!open) {
+ if (open) {
+ // 打开时,默认选中当前 activeKey 对应的 tab
+ if (!selectedKey && activeKey) {
+ setSelectedKey(activeKey);
+ }
+ } else {
setSelectedKey(null);
+ if (autoClearSearchValue && controlledSearchValue === undefined) {
+ setSearchValue('');
+ }
}
- }, [open]);
+ }, [open, activeKey]);
// ========================= Render =========================
const moreStyle: React.CSSProperties = {
@@ -193,10 +256,23 @@ const OperationNode = React.forwardRef((prop
const overlayClassName = clsx(popupClassName, { [`${dropdownPrefix}-rtl`]: rtl });
+ // 搜索框包裹 menu
+ const dropdownContent = isSearchable ? (
+
+ {searchInput}
+ {menu}
+
+ ) : (
+ menu
+ );
+
+ // 过滤 showSearch 属性,避免传给 Dropdown
+ const { showSearch: _s, ...dropdownProps } = moreProps;
+
const moreNode: React.ReactNode = mobile ? null : (
((prop
mouseEnterDelay={0.1}
mouseLeaveDelay={0.1}
getPopupContainer={getPopupContainer}
- {...moreProps}
+ {...dropdownProps}
>