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

feat(portal): enable global 'body' override for Portal's appendTo #5134

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions components/lib/config/PrimeVue.d.ts
Expand Up @@ -96,6 +96,7 @@ import { TreeTablePassThroughOptions } from '../treetable';
import { TriStateCheckboxPassThroughOptions } from '../tristatecheckbox';
import { DefaultPassThrough, PassThrough } from '../ts-helpers';
import { VirtualScrollerPassThroughOptions } from '../virtualscroller';
import { PortalAppendToType } from '../portal/Portal';

export interface PrimeVueConfiguration {
ripple?: boolean;
Expand All @@ -107,6 +108,12 @@ export interface PrimeVueConfiguration {
ptOptions?: PassThroughOptions;
unstyled?: boolean;
csp?: PrimeVueCSPOptions;
/**
* A valid query selector or an HTMLElement to specify where the dialog gets attached. Special keywords are 'body' for document body and 'self' for the element itself.
* @see PortalAppendToType
* Default value is 'body'.
*/
appendTo?: PortalAppendToType
}

export declare const defaultOptions: PrimeVueConfiguration;
Expand Down
3 changes: 2 additions & 1 deletion components/lib/config/PrimeVue.js
Expand Up @@ -141,7 +141,8 @@ export const defaultOptions = {
unstyled: false,
csp: {
nonce: undefined
}
},
appendTo: 'body'
};

const PrimeVueSymbol = Symbol();
Expand Down
6 changes: 3 additions & 3 deletions components/lib/portal/Portal.d.ts
@@ -1,7 +1,7 @@
import { VNode } from 'vue';
import { Ref, VNode } from 'vue';
import { ClassComponent, GlobalComponentConstructor } from '../ts-helpers';

type PortalAppendToType = 'body' | 'self' | string | undefined | HTMLElement;
export type PortalAppendToType = 'body' | 'self' | string | undefined | HTMLElement;

export interface PortalProps {
/**
Expand All @@ -26,7 +26,7 @@ export interface PortalSlots {

export declare type PortalEmits = {};

declare class Portal extends ClassComponent<PortalProps, PortalSlots, PortalEmits> {}
declare class Portal extends ClassComponent<PortalProps, PortalSlots, PortalEmits> { }

declare module '@vue/runtime-core' {
interface GlobalComponents {
Expand Down
5 changes: 4 additions & 1 deletion components/lib/portal/Portal.vue
Expand Up @@ -3,7 +3,7 @@
<slot></slot>
</template>
<template v-else-if="mounted">
<Teleport :to="appendTo">
<Teleport :to="to">
<slot></slot>
</Teleport>
</template>
Expand Down Expand Up @@ -33,6 +33,9 @@ export default {
this.mounted = DomHandler.isClient();
},
computed: {
to() {
return this.appendTo === 'body' ? this.$primeVue.config.appendTo ?? this.appendTo : this.appendTo;
},
inline() {
return this.disabled || this.appendTo === 'self';
}
Expand Down