fix: picker support v-show

pull/6577/head
tangjinzhou 2023-05-17 22:53:02 +08:00
parent 429172b345
commit 5aad611d4c
4 changed files with 142 additions and 139 deletions

View File

@ -589,47 +589,57 @@ function Picker<DateType>() {
const popupPlacement = direction === 'rtl' ? 'bottomRight' : 'bottomLeft'; const popupPlacement = direction === 'rtl' ? 'bottomRight' : 'bottomLeft';
return ( return (
<PickerTrigger <div
visible={mergedOpen.value} ref={containerRef}
popupStyle={popupStyle} class={classNames(prefixCls, attrs.class, {
prefixCls={prefixCls} [`${prefixCls}-disabled`]: disabled,
dropdownClassName={dropdownClassName} [`${prefixCls}-focused`]: focused.value,
dropdownAlign={dropdownAlign} [`${prefixCls}-rtl`]: direction === 'rtl',
getPopupContainer={getPopupContainer} })}
transitionName={transitionName} style={attrs.style as CSSProperties}
popupPlacement={popupPlacement} onMousedown={onMousedown}
direction={direction} onMouseup={onInternalMouseup}
v-slots={{ onMouseenter={onMouseenter}
popupElement: () => panel, onMouseleave={onMouseleave}
}} onContextmenu={onContextmenu}
onClick={onClick}
> >
<div <div
ref={containerRef} class={classNames(`${prefixCls}-input`, {
class={classNames(prefixCls, attrs.class, { [`${prefixCls}-input-placeholder`]: !!hoverValue.value,
[`${prefixCls}-disabled`]: disabled,
[`${prefixCls}-focused`]: focused.value,
[`${prefixCls}-rtl`]: direction === 'rtl',
})} })}
style={attrs.style as CSSProperties} ref={inputDivRef}
onMousedown={onMousedown} >
onMouseup={onInternalMouseup} {inputNode}
onMouseenter={onMouseenter} {suffixNode}
onMouseleave={onMouseleave} {clearNode}
onContextmenu={onContextmenu} </div>
onClick={onClick} <PickerTrigger
visible={mergedOpen.value}
popupStyle={popupStyle}
prefixCls={prefixCls}
dropdownClassName={dropdownClassName}
dropdownAlign={dropdownAlign}
getPopupContainer={getPopupContainer}
transitionName={transitionName}
popupPlacement={popupPlacement}
direction={direction}
v-slots={{
popupElement: () => panel,
}}
> >
<div <div
class={classNames(`${prefixCls}-input`, { style={{
[`${prefixCls}-input-placeholder`]: !!hoverValue.value, pointerEvents: 'none',
})} position: 'absolute',
ref={inputDivRef} top: 0,
> bottom: 0,
{inputNode} left: 0,
{suffixNode} right: 0,
{clearNode} }}
</div> ></div>
</div> </PickerTrigger>
</PickerTrigger> </div>
); );
}; };
}, },

View File

@ -1205,99 +1205,109 @@ function RangerPicker<DateType>() {
// ============================ Return ============================= // ============================ Return =============================
return ( return (
<PickerTrigger <div
visible={mergedOpen.value} ref={containerRef}
popupStyle={popupStyle} class={classNames(prefixCls, `${prefixCls}-range`, attrs.class, {
prefixCls={prefixCls} [`${prefixCls}-disabled`]: mergedDisabled.value[0] && mergedDisabled.value[1],
dropdownClassName={dropdownClassName} [`${prefixCls}-focused`]:
dropdownAlign={dropdownAlign} mergedActivePickerIndex.value === 0 ? startFocused.value : endFocused.value,
getPopupContainer={getPopupContainer} [`${prefixCls}-rtl`]: direction === 'rtl',
transitionName={transitionName} })}
range style={attrs.style}
direction={direction} onClick={onPickerClick}
v-slots={{ onMouseenter={onMouseenter}
popupElement: () => rangePanel, onMouseleave={onMouseleave}
}} onMousedown={onPickerMousedown}
onMouseup={onMouseup}
{...getDataOrAriaProps(props)}
> >
<div <div
ref={containerRef} class={classNames(`${prefixCls}-input`, {
class={classNames(prefixCls, `${prefixCls}-range`, attrs.class, { [`${prefixCls}-input-active`]: mergedActivePickerIndex.value === 0,
[`${prefixCls}-disabled`]: mergedDisabled.value[0] && mergedDisabled.value[1], [`${prefixCls}-input-placeholder`]: !!startHoverValue.value,
[`${prefixCls}-focused`]:
mergedActivePickerIndex.value === 0 ? startFocused.value : endFocused.value,
[`${prefixCls}-rtl`]: direction === 'rtl',
})} })}
style={attrs.style} ref={startInputDivRef}
onClick={onPickerClick} >
onMouseenter={onMouseenter} <input
onMouseleave={onMouseleave} id={id}
onMousedown={onPickerMousedown} disabled={mergedDisabled.value[0]}
onMouseup={onMouseup} readonly={
{...getDataOrAriaProps(props)} inputReadOnly || typeof formatList.value[0] === 'function' || !startTyping.value
}
value={startHoverValue.value || startText.value}
onInput={(e: ChangeEvent) => {
triggerStartTextChange(e.target.value);
}}
autofocus={autofocus}
placeholder={getValue(placeholder, 0) || ''}
ref={startInputRef}
{...startInputProps.value}
{...inputSharedProps}
autocomplete={autocomplete}
/>
</div>
<div class={`${prefixCls}-range-separator`} ref={separatorRef}>
{separator}
</div>
<div
class={classNames(`${prefixCls}-input`, {
[`${prefixCls}-input-active`]: mergedActivePickerIndex.value === 1,
[`${prefixCls}-input-placeholder`]: !!endHoverValue.value,
})}
ref={endInputDivRef}
>
<input
disabled={mergedDisabled.value[1]}
readonly={
inputReadOnly || typeof formatList.value[0] === 'function' || !endTyping.value
}
value={endHoverValue.value || endText.value}
onInput={(e: ChangeEvent) => {
triggerEndTextChange(e.target.value);
}}
placeholder={getValue(placeholder, 1) || ''}
ref={endInputRef}
{...endInputProps.value}
{...inputSharedProps}
autocomplete={autocomplete}
/>
</div>
<div
class={`${prefixCls}-active-bar`}
style={{
...activeBarPositionStyle,
width: `${activeBarWidth}px`,
position: 'absolute',
}}
/>
{suffixNode}
{clearNode}
<PickerTrigger
visible={mergedOpen.value}
popupStyle={popupStyle}
prefixCls={prefixCls}
dropdownClassName={dropdownClassName}
dropdownAlign={dropdownAlign}
getPopupContainer={getPopupContainer}
transitionName={transitionName}
range
direction={direction}
v-slots={{
popupElement: () => rangePanel,
}}
> >
<div <div
class={classNames(`${prefixCls}-input`, {
[`${prefixCls}-input-active`]: mergedActivePickerIndex.value === 0,
[`${prefixCls}-input-placeholder`]: !!startHoverValue.value,
})}
ref={startInputDivRef}
>
<input
id={id}
disabled={mergedDisabled.value[0]}
readonly={
inputReadOnly || typeof formatList.value[0] === 'function' || !startTyping.value
}
value={startHoverValue.value || startText.value}
onInput={(e: ChangeEvent) => {
triggerStartTextChange(e.target.value);
}}
autofocus={autofocus}
placeholder={getValue(placeholder, 0) || ''}
ref={startInputRef}
{...startInputProps.value}
{...inputSharedProps}
autocomplete={autocomplete}
/>
</div>
<div class={`${prefixCls}-range-separator`} ref={separatorRef}>
{separator}
</div>
<div
class={classNames(`${prefixCls}-input`, {
[`${prefixCls}-input-active`]: mergedActivePickerIndex.value === 1,
[`${prefixCls}-input-placeholder`]: !!endHoverValue.value,
})}
ref={endInputDivRef}
>
<input
disabled={mergedDisabled.value[1]}
readonly={
inputReadOnly || typeof formatList.value[0] === 'function' || !endTyping.value
}
value={endHoverValue.value || endText.value}
onInput={(e: ChangeEvent) => {
triggerEndTextChange(e.target.value);
}}
placeholder={getValue(placeholder, 1) || ''}
ref={endInputRef}
{...endInputProps.value}
{...inputSharedProps}
autocomplete={autocomplete}
/>
</div>
<div
class={`${prefixCls}-active-bar`}
style={{ style={{
...activeBarPositionStyle, pointerEvents: 'none',
width: `${activeBarWidth}px`,
position: 'absolute', position: 'absolute',
top: 0,
bottom: 0,
left: 0,
right: 0,
}} }}
/> ></div>
{suffixNode} </PickerTrigger>
{clearNode} </div>
</div>
</PickerTrigger>
); );
}; };
}, },

View File

@ -701,8 +701,8 @@ export default defineComponent({
); );
return ( return (
<> <>
{portal}
{trigger} {trigger}
{portal}
</> </>
); );
}, },

View File

@ -1,22 +1,5 @@
import type { InjectionKey, Ref } from 'vue'; import type { InjectionKey, Ref } from 'vue';
import { computed, inject, provide } from 'vue'; import { computed, inject, provide } from 'vue';
export interface TriggerContextProps {
setPortal: (val?: any) => void;
popPortal: boolean; // 将 portal 上传至父级元素渲染,不用考虑响应式
}
const TriggerContextKey: InjectionKey<TriggerContextProps> = Symbol('TriggerContextKey');
export const useProviderTrigger = () => {
let portal = null;
provide(TriggerContextKey, {
setPortal(val) {
portal = val;
},
popPortal: true,
});
return () => {
return portal;
};
};
export interface PortalContextProps { export interface PortalContextProps {
shouldRender: Ref<boolean>; shouldRender: Ref<boolean>;