mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-05 19:41:42 +08:00
fix(Popover): allow to dynamically set offset prop (#10840)
This commit is contained in:
parent
c628a66770
commit
794fd029a0
@ -93,25 +93,31 @@ export default defineComponent({
|
||||
const wrapperRef = ref<HTMLElement>();
|
||||
const popoverRef = ref<ComponentInstance>();
|
||||
|
||||
const getPopoverOptions = () => ({
|
||||
placement: props.placement,
|
||||
modifiers: [
|
||||
{
|
||||
name: 'computeStyles',
|
||||
options: {
|
||||
adaptive: false,
|
||||
gpuAcceleration: false,
|
||||
},
|
||||
},
|
||||
extend({}, offsetModifier, {
|
||||
options: {
|
||||
offset: props.offset,
|
||||
},
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
const createPopperInstance = () => {
|
||||
if (wrapperRef.value && popoverRef.value) {
|
||||
return createPopper(wrapperRef.value, popoverRef.value.popupRef.value, {
|
||||
placement: props.placement,
|
||||
modifiers: [
|
||||
{
|
||||
name: 'computeStyles',
|
||||
options: {
|
||||
adaptive: false,
|
||||
gpuAcceleration: false,
|
||||
},
|
||||
},
|
||||
extend({}, offsetModifier, {
|
||||
options: {
|
||||
offset: props.offset,
|
||||
},
|
||||
}),
|
||||
],
|
||||
});
|
||||
return createPopper(
|
||||
wrapperRef.value,
|
||||
popoverRef.value.popupRef.value,
|
||||
getPopoverOptions()
|
||||
);
|
||||
}
|
||||
return null;
|
||||
};
|
||||
@ -125,9 +131,7 @@ export default defineComponent({
|
||||
if (!popper) {
|
||||
popper = createPopperInstance();
|
||||
} else {
|
||||
popper.setOptions({
|
||||
placement: props.placement,
|
||||
});
|
||||
popper.setOptions(getPopoverOptions());
|
||||
}
|
||||
});
|
||||
};
|
||||
@ -207,7 +211,7 @@ export default defineComponent({
|
||||
}
|
||||
});
|
||||
|
||||
watch(() => [props.show, props.placement], updateLocation);
|
||||
watch(() => [props.show, props.offset, props.placement], updateLocation);
|
||||
|
||||
useClickAway(wrapperRef, onClickAway, { eventName: 'touchstart' });
|
||||
|
||||
|
@ -85,6 +85,17 @@ const show = ref({
|
||||
const showPicker = ref(false);
|
||||
const currentPlacement = ref<PopoverPlacement>('top');
|
||||
|
||||
const onClickChoosePlacement = () => {
|
||||
showPicker.value = true;
|
||||
|
||||
setTimeout(() => {
|
||||
show.value = {
|
||||
...show.value,
|
||||
placement: true,
|
||||
};
|
||||
}, 300);
|
||||
};
|
||||
|
||||
const onPickerChange = (value: PopoverPlacement) => {
|
||||
setTimeout(() => {
|
||||
show.value.placement = true;
|
||||
@ -129,7 +140,7 @@ const onSelect = (action: { text: string }) => Toast(action.text);
|
||||
readonly
|
||||
name="picker"
|
||||
:label="t('choosePlacement')"
|
||||
@click="showPicker = true"
|
||||
@click="onClickChoosePlacement"
|
||||
/>
|
||||
|
||||
<van-popup
|
||||
|
Loading…
x
Reference in New Issue
Block a user