Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(color-picker): 选择色值mode的popup隐藏问题 #1914

Merged
merged 1 commit into from
Jan 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 1 addition & 14 deletions src/color-picker/ColorPicker.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import React, { useState, useRef } from 'react';
import React, { useRef } from 'react';
import { Popup, PopupProps } from '../popup';
import { ColorPickerProps, TdColorContext } from './interface';
import useClassName from './hooks/useClassNames';
import useControlled from '../hooks/useControlled';
import ColorTrigger from './components/trigger';
import ColorPanel from './components/panel/index';
import useClickOutside from '../_util/useClickOutside';
import { colorPickerDefaultProps } from './defaultProps';

const ColorPicker: React.FC<ColorPickerProps> = (props) => {
const baseClassName = useClassName();
const { popupProps, disabled, inputProps, onChange, colorModes, ...rest } = props;
const { overlayClassName, overlayInnerStyle = {}, ...restPopupProps } = popupProps || {};

const [visible, setVisible] = useState(false);
const [innerValue, setInnerValue] = useControlled(props, 'value', onChange);
const triggerRef = useRef<HTMLDivElement>();
const colorPanelRef = useRef();
Expand All @@ -22,7 +20,6 @@ const ColorPicker: React.FC<ColorPickerProps> = (props) => {
placement: 'bottom-left',
expandAnimation: true,
trigger: 'click',
visible,
...restPopupProps,
overlayClassName: [baseClassName, overlayClassName],
overlayInnerStyle: {
Expand All @@ -31,26 +28,16 @@ const ColorPicker: React.FC<ColorPickerProps> = (props) => {
},
};

useClickOutside(
[triggerRef, colorPanelRef],
() => {
setVisible(false);
},
true,
);

return (
<Popup
{...popProps}
onVisibleChange={(v) => setVisible(v)}
content={
!disabled && (
<ColorPanel
{...rest}
disabled={disabled}
value={innerValue}
colorModes={colorModes}
togglePopup={setVisible}
onChange={(value: string, context: TdColorContext) => setInnerValue(value, context)}
ref={colorPanelRef}
/>
Expand Down