Skip to content

Commit 5aad611

Browse files
committed
fix: picker support v-show
1 parent 429172b commit 5aad611

File tree

4 files changed

+142
-139
lines changed

4 files changed

+142
-139
lines changed

components/vc-picker/Picker.tsx

+46-36
Original file line numberDiff line numberDiff line change
@@ -589,47 +589,57 @@ function Picker<DateType>() {
589589

590590
const popupPlacement = direction === 'rtl' ? 'bottomRight' : 'bottomLeft';
591591
return (
592-
<PickerTrigger
593-
visible={mergedOpen.value}
594-
popupStyle={popupStyle}
595-
prefixCls={prefixCls}
596-
dropdownClassName={dropdownClassName}
597-
dropdownAlign={dropdownAlign}
598-
getPopupContainer={getPopupContainer}
599-
transitionName={transitionName}
600-
popupPlacement={popupPlacement}
601-
direction={direction}
602-
v-slots={{
603-
popupElement: () => panel,
604-
}}
592+
<div
593+
ref={containerRef}
594+
class={classNames(prefixCls, attrs.class, {
595+
[`${prefixCls}-disabled`]: disabled,
596+
[`${prefixCls}-focused`]: focused.value,
597+
[`${prefixCls}-rtl`]: direction === 'rtl',
598+
})}
599+
style={attrs.style as CSSProperties}
600+
onMousedown={onMousedown}
601+
onMouseup={onInternalMouseup}
602+
onMouseenter={onMouseenter}
603+
onMouseleave={onMouseleave}
604+
onContextmenu={onContextmenu}
605+
onClick={onClick}
605606
>
606607
<div
607-
ref={containerRef}
608-
class={classNames(prefixCls, attrs.class, {
609-
[`${prefixCls}-disabled`]: disabled,
610-
[`${prefixCls}-focused`]: focused.value,
611-
[`${prefixCls}-rtl`]: direction === 'rtl',
608+
class={classNames(`${prefixCls}-input`, {
609+
[`${prefixCls}-input-placeholder`]: !!hoverValue.value,
612610
})}
613-
style={attrs.style as CSSProperties}
614-
onMousedown={onMousedown}
615-
onMouseup={onInternalMouseup}
616-
onMouseenter={onMouseenter}
617-
onMouseleave={onMouseleave}
618-
onContextmenu={onContextmenu}
619-
onClick={onClick}
611+
ref={inputDivRef}
620612
>
621-
<div
622-
class={classNames(`${prefixCls}-input`, {
623-
[`${prefixCls}-input-placeholder`]: !!hoverValue.value,
624-
})}
625-
ref={inputDivRef}
626-
>
627-
{inputNode}
628-
{suffixNode}
629-
{clearNode}
630-
</div>
613+
{inputNode}
614+
{suffixNode}
615+
{clearNode}
631616
</div>
632-
</PickerTrigger>
617+
<PickerTrigger
618+
visible={mergedOpen.value}
619+
popupStyle={popupStyle}
620+
prefixCls={prefixCls}
621+
dropdownClassName={dropdownClassName}
622+
dropdownAlign={dropdownAlign}
623+
getPopupContainer={getPopupContainer}
624+
transitionName={transitionName}
625+
popupPlacement={popupPlacement}
626+
direction={direction}
627+
v-slots={{
628+
popupElement: () => panel,
629+
}}
630+
>
631+
<div
632+
style={{
633+
pointerEvents: 'none',
634+
position: 'absolute',
635+
top: 0,
636+
bottom: 0,
637+
left: 0,
638+
right: 0,
639+
}}
640+
></div>
641+
</PickerTrigger>
642+
</div>
633643
);
634644
};
635645
},

components/vc-picker/RangePicker.tsx

+95-85
Original file line numberDiff line numberDiff line change
@@ -1205,99 +1205,109 @@ function RangerPicker<DateType>() {
12051205
// ============================ Return =============================
12061206

12071207
return (
1208-
<PickerTrigger
1209-
visible={mergedOpen.value}
1210-
popupStyle={popupStyle}
1211-
prefixCls={prefixCls}
1212-
dropdownClassName={dropdownClassName}
1213-
dropdownAlign={dropdownAlign}
1214-
getPopupContainer={getPopupContainer}
1215-
transitionName={transitionName}
1216-
range
1217-
direction={direction}
1218-
v-slots={{
1219-
popupElement: () => rangePanel,
1220-
}}
1208+
<div
1209+
ref={containerRef}
1210+
class={classNames(prefixCls, `${prefixCls}-range`, attrs.class, {
1211+
[`${prefixCls}-disabled`]: mergedDisabled.value[0] && mergedDisabled.value[1],
1212+
[`${prefixCls}-focused`]:
1213+
mergedActivePickerIndex.value === 0 ? startFocused.value : endFocused.value,
1214+
[`${prefixCls}-rtl`]: direction === 'rtl',
1215+
})}
1216+
style={attrs.style}
1217+
onClick={onPickerClick}
1218+
onMouseenter={onMouseenter}
1219+
onMouseleave={onMouseleave}
1220+
onMousedown={onPickerMousedown}
1221+
onMouseup={onMouseup}
1222+
{...getDataOrAriaProps(props)}
12211223
>
12221224
<div
1223-
ref={containerRef}
1224-
class={classNames(prefixCls, `${prefixCls}-range`, attrs.class, {
1225-
[`${prefixCls}-disabled`]: mergedDisabled.value[0] && mergedDisabled.value[1],
1226-
[`${prefixCls}-focused`]:
1227-
mergedActivePickerIndex.value === 0 ? startFocused.value : endFocused.value,
1228-
[`${prefixCls}-rtl`]: direction === 'rtl',
1225+
class={classNames(`${prefixCls}-input`, {
1226+
[`${prefixCls}-input-active`]: mergedActivePickerIndex.value === 0,
1227+
[`${prefixCls}-input-placeholder`]: !!startHoverValue.value,
12291228
})}
1230-
style={attrs.style}
1231-
onClick={onPickerClick}
1232-
onMouseenter={onMouseenter}
1233-
onMouseleave={onMouseleave}
1234-
onMousedown={onPickerMousedown}
1235-
onMouseup={onMouseup}
1236-
{...getDataOrAriaProps(props)}
1229+
ref={startInputDivRef}
1230+
>
1231+
<input
1232+
id={id}
1233+
disabled={mergedDisabled.value[0]}
1234+
readonly={
1235+
inputReadOnly || typeof formatList.value[0] === 'function' || !startTyping.value
1236+
}
1237+
value={startHoverValue.value || startText.value}
1238+
onInput={(e: ChangeEvent) => {
1239+
triggerStartTextChange(e.target.value);
1240+
}}
1241+
autofocus={autofocus}
1242+
placeholder={getValue(placeholder, 0) || ''}
1243+
ref={startInputRef}
1244+
{...startInputProps.value}
1245+
{...inputSharedProps}
1246+
autocomplete={autocomplete}
1247+
/>
1248+
</div>
1249+
<div class={`${prefixCls}-range-separator`} ref={separatorRef}>
1250+
{separator}
1251+
</div>
1252+
<div
1253+
class={classNames(`${prefixCls}-input`, {
1254+
[`${prefixCls}-input-active`]: mergedActivePickerIndex.value === 1,
1255+
[`${prefixCls}-input-placeholder`]: !!endHoverValue.value,
1256+
})}
1257+
ref={endInputDivRef}
1258+
>
1259+
<input
1260+
disabled={mergedDisabled.value[1]}
1261+
readonly={
1262+
inputReadOnly || typeof formatList.value[0] === 'function' || !endTyping.value
1263+
}
1264+
value={endHoverValue.value || endText.value}
1265+
onInput={(e: ChangeEvent) => {
1266+
triggerEndTextChange(e.target.value);
1267+
}}
1268+
placeholder={getValue(placeholder, 1) || ''}
1269+
ref={endInputRef}
1270+
{...endInputProps.value}
1271+
{...inputSharedProps}
1272+
autocomplete={autocomplete}
1273+
/>
1274+
</div>
1275+
<div
1276+
class={`${prefixCls}-active-bar`}
1277+
style={{
1278+
...activeBarPositionStyle,
1279+
width: `${activeBarWidth}px`,
1280+
position: 'absolute',
1281+
}}
1282+
/>
1283+
{suffixNode}
1284+
{clearNode}
1285+
<PickerTrigger
1286+
visible={mergedOpen.value}
1287+
popupStyle={popupStyle}
1288+
prefixCls={prefixCls}
1289+
dropdownClassName={dropdownClassName}
1290+
dropdownAlign={dropdownAlign}
1291+
getPopupContainer={getPopupContainer}
1292+
transitionName={transitionName}
1293+
range
1294+
direction={direction}
1295+
v-slots={{
1296+
popupElement: () => rangePanel,
1297+
}}
12371298
>
12381299
<div
1239-
class={classNames(`${prefixCls}-input`, {
1240-
[`${prefixCls}-input-active`]: mergedActivePickerIndex.value === 0,
1241-
[`${prefixCls}-input-placeholder`]: !!startHoverValue.value,
1242-
})}
1243-
ref={startInputDivRef}
1244-
>
1245-
<input
1246-
id={id}
1247-
disabled={mergedDisabled.value[0]}
1248-
readonly={
1249-
inputReadOnly || typeof formatList.value[0] === 'function' || !startTyping.value
1250-
}
1251-
value={startHoverValue.value || startText.value}
1252-
onInput={(e: ChangeEvent) => {
1253-
triggerStartTextChange(e.target.value);
1254-
}}
1255-
autofocus={autofocus}
1256-
placeholder={getValue(placeholder, 0) || ''}
1257-
ref={startInputRef}
1258-
{...startInputProps.value}
1259-
{...inputSharedProps}
1260-
autocomplete={autocomplete}
1261-
/>
1262-
</div>
1263-
<div class={`${prefixCls}-range-separator`} ref={separatorRef}>
1264-
{separator}
1265-
</div>
1266-
<div
1267-
class={classNames(`${prefixCls}-input`, {
1268-
[`${prefixCls}-input-active`]: mergedActivePickerIndex.value === 1,
1269-
[`${prefixCls}-input-placeholder`]: !!endHoverValue.value,
1270-
})}
1271-
ref={endInputDivRef}
1272-
>
1273-
<input
1274-
disabled={mergedDisabled.value[1]}
1275-
readonly={
1276-
inputReadOnly || typeof formatList.value[0] === 'function' || !endTyping.value
1277-
}
1278-
value={endHoverValue.value || endText.value}
1279-
onInput={(e: ChangeEvent) => {
1280-
triggerEndTextChange(e.target.value);
1281-
}}
1282-
placeholder={getValue(placeholder, 1) || ''}
1283-
ref={endInputRef}
1284-
{...endInputProps.value}
1285-
{...inputSharedProps}
1286-
autocomplete={autocomplete}
1287-
/>
1288-
</div>
1289-
<div
1290-
class={`${prefixCls}-active-bar`}
12911300
style={{
1292-
...activeBarPositionStyle,
1293-
width: `${activeBarWidth}px`,
1301+
pointerEvents: 'none',
12941302
position: 'absolute',
1303+
top: 0,
1304+
bottom: 0,
1305+
left: 0,
1306+
right: 0,
12951307
}}
1296-
/>
1297-
{suffixNode}
1298-
{clearNode}
1299-
</div>
1300-
</PickerTrigger>
1308+
></div>
1309+
</PickerTrigger>
1310+
</div>
13011311
);
13021312
};
13031313
},

components/vc-trigger/Trigger.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -701,8 +701,8 @@ export default defineComponent({
701701
);
702702
return (
703703
<>
704-
{portal}
705704
{trigger}
705+
{portal}
706706
</>
707707
);
708708
},

components/vc-trigger/context.ts

-17
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,5 @@
11
import type { InjectionKey, Ref } from 'vue';
22
import { computed, inject, provide } from 'vue';
3-
export interface TriggerContextProps {
4-
setPortal: (val?: any) => void;
5-
popPortal: boolean; // 将 portal 上传至父级元素渲染,不用考虑响应式
6-
}
7-
const TriggerContextKey: InjectionKey<TriggerContextProps> = Symbol('TriggerContextKey');
8-
export const useProviderTrigger = () => {
9-
let portal = null;
10-
provide(TriggerContextKey, {
11-
setPortal(val) {
12-
portal = val;
13-
},
14-
popPortal: true,
15-
});
16-
return () => {
17-
return portal;
18-
};
19-
};
203

214
export interface PortalContextProps {
225
shouldRender: Ref<boolean>;

0 commit comments

Comments
 (0)