mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-25 22:38:56 +08:00
fix: close select popover after mouse leave code block
This commit is contained in:
@@ -5,6 +5,7 @@ import {
|
||||
type ForwardedRef,
|
||||
type ReactNode,
|
||||
type RefAttributes,
|
||||
useEffect,
|
||||
} from 'react';
|
||||
/* eslint-disable no-restricted-imports */
|
||||
import SelectUnstyled, {
|
||||
@@ -15,13 +16,13 @@ import SelectUnstyled, {
|
||||
import PopperUnstyled from '@mui/base/PopperUnstyled';
|
||||
import { ArrowDropDownIcon } from '@toeverything/components/icons';
|
||||
import { styled } from '../styled';
|
||||
|
||||
type ExtendSelectProps = {
|
||||
// Width is always used custom, it will be set to root button and popover
|
||||
width?: number | string;
|
||||
style?: CSSProperties;
|
||||
listboxStyle?: CSSProperties;
|
||||
placeholder?: ReactNode;
|
||||
open?: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -40,7 +41,6 @@ export const Select = forwardRef(function CustomSelect<TValue>(
|
||||
props: ExtendSelectProps & SelectUnstyledProps<TValue>,
|
||||
ref: ForwardedRef<HTMLUListElement>
|
||||
) {
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
const {
|
||||
width = '100%',
|
||||
style,
|
||||
@@ -48,7 +48,11 @@ export const Select = forwardRef(function CustomSelect<TValue>(
|
||||
placeholder,
|
||||
onListboxOpenChange,
|
||||
onChange,
|
||||
open: propsOpen,
|
||||
} = props;
|
||||
const openControlledByProps = propsOpen !== undefined;
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
|
||||
const components: SelectUnstyledProps<TValue>['components'] = {
|
||||
// Root: generateStyledRoot({ width, ...style }),
|
||||
Root: forwardRef((rootProps, rootRef) => {
|
||||
@@ -88,13 +92,13 @@ export const Select = forwardRef(function CustomSelect<TValue>(
|
||||
return (
|
||||
<SelectUnstyled
|
||||
{...props}
|
||||
listboxOpen={isOpen}
|
||||
listboxOpen={openControlledByProps ? propsOpen : isOpen}
|
||||
onListboxOpenChange={open => {
|
||||
setIsOpen(open);
|
||||
!openControlledByProps && setIsOpen(open);
|
||||
onListboxOpenChange?.(open);
|
||||
}}
|
||||
onChange={v => {
|
||||
setIsOpen(false);
|
||||
!openControlledByProps && setIsOpen(false);
|
||||
onChange?.(v);
|
||||
}}
|
||||
ref={ref}
|
||||
|
||||
Reference in New Issue
Block a user