Skip to content

Commit b583d76

Browse files
committed
refactor!: Use slots filtering when shadowDom is set explicitly (fixes #922)
1 parent 03ef0c9 commit b583d76

File tree

4 files changed

+28
-20
lines changed

4 files changed

+28
-20
lines changed

index.d.ts

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,23 @@ export interface UIOptions {
121121
input: CustomClass;
122122
}
123123

124+
export interface GeneralConfig {
125+
allowStopPropagation?: boolean;
126+
closeOnScroll?: boolean;
127+
modeHeight?: number;
128+
allowPreventDefault?: boolean;
129+
closeOnClearValue?: boolean;
130+
closeOnAutoApply?: boolean;
131+
noSwipe?: boolean;
132+
keepActionRow?: boolean;
133+
onClickOutside?: (validate: () => boolean) => void;
134+
tabOutClosesMenu?: boolean;
135+
arrowLeft?: string;
136+
keepViewOnOffsetClick?: boolean;
137+
timeArrowHoldThreshold?: boolean;
138+
shadowDom?: boolean;
139+
}
140+
124141
export interface VueDatePickerProps {
125142
uid?: string;
126143
name?: string;
@@ -283,21 +300,7 @@ export interface VueDatePickerProps {
283300
| [DisabledTime[], DisabledTime[]];
284301
timePickerInline?: boolean;
285302
calendar?: (weeks: CalendarWeek[]) => CalendarWeek[];
286-
config?: {
287-
allowStopPropagation?: boolean;
288-
closeOnScroll?: boolean;
289-
modeHeight?: number;
290-
allowPreventDefault?: boolean;
291-
closeOnClearValue?: boolean;
292-
closeOnAutoApply?: boolean;
293-
noSwipe?: boolean;
294-
keepActionRow?: boolean;
295-
onClickOutside?: (validate: () => boolean) => void;
296-
tabOutClosesMenu?: boolean;
297-
arrowLeft?: string;
298-
keepViewOnOffsetClick?: boolean;
299-
timeArrowHoldThreshold?: boolean;
300-
};
303+
config?: GeneralConfig;
301304
quarterPicker?: boolean;
302305
yearFirst?: boolean;
303306
loading?: boolean;

src/VueDatePicker/composables/position.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { MenuPlacement } from '@/constants';
1313

1414
import type { Component, ComputedRef, Ref, Slots } from 'vue';
1515
import type { AllPropsType } from '@/props';
16+
import { useDefaults } from '@/composables/defaults';
1617

1718
/**
1819
* Extracted code from the main component, used for calculating the position of the menu
@@ -37,6 +38,7 @@ export const usePosition = ({
3738
props,
3839
slots,
3940
}: Params) => {
41+
const { defaultedConfig } = useDefaults(props);
4042
const menuRect = ref<DOMRect>({} as DOMRect);
4143
const xCorrect = ref(false);
4244

@@ -257,6 +259,11 @@ export const usePosition = ({
257259
wrap.append(container);
258260

259261
const pos = getShadowPos(input);
262+
const mappedSlots = defaultedConfig.value.shadowDom
263+
? Object.keys(slots).filter((slot) =>
264+
['right-sidebar', 'left-sidebar', 'top-extra', 'action-extra'].includes(slot),
265+
)
266+
: Object.keys(slots);
260267

261268
const el = h(
262269
DPMenu,
@@ -265,11 +272,7 @@ export const usePosition = ({
265272
shadow: true,
266273
style: { opacity: 0, position: 'absolute', ...pos },
267274
},
268-
Object.fromEntries(
269-
Object.keys(slots)
270-
.filter((slot) => ['right-sidebar', 'left-sidebar', 'top-extra', 'action-extra'].includes(slot))
271-
.map((slot) => [slot, slots[slot]]),
272-
),
275+
Object.fromEntries(mappedSlots.map((slot) => [slot, slots[slot]])),
273276
);
274277

275278
render(el, container);

src/VueDatePicker/interfaces.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ export interface Config {
292292
arrowLeft?: string;
293293
keepViewOnOffsetClick?: boolean;
294294
timeArrowHoldThreshold: number;
295+
shadowDom?: boolean;
295296
}
296297

297298
export interface Highlight {

src/VueDatePicker/utils/defaults.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ export const getDefaultConfig = (config?: Partial<Config>): Config => {
174174
arrowLeft: undefined,
175175
keepViewOnOffsetClick: false,
176176
timeArrowHoldThreshold: 0,
177+
shadowDom: false,
177178
};
178179
return { ...defaultConfig, ...(config ?? {}) };
179180
};

0 commit comments

Comments
 (0)