Skip to content

Commit

Permalink
feat:appendTo support function (#5576)
Browse files Browse the repository at this point in the history
  • Loading branch information
kl-nevermore authored Dec 12, 2023
1 parent ac25511 commit 53df7c9
Show file tree
Hide file tree
Showing 27 changed files with 39 additions and 29 deletions.
2 changes: 1 addition & 1 deletion components/lib/api/api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export interface ZIndexOptions {

export type InputStyleType = 'outlined' | 'filled';

export type AppendToType = 'self' | HTMLElement | undefined | null;
export type AppendToType = 'self' | HTMLElement | undefined | null | (() => HTMLElement);

/**
* Filter match modes for DataTable filter menus.
Expand Down
2 changes: 1 addition & 1 deletion components/lib/autocomplete/autocomplete.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ export interface AutoCompleteProps extends Omit<React.DetailedHTMLProps<React.HT
* DOM element instance where the overlay panel should be mounted. Valid values are any DOM Element and "self". The "self" value is used to render a component where it is located.
* @defaultValue document.body
*/
appendTo?: 'self' | HTMLElement | undefined | null;
appendTo?: 'self' | HTMLElement | undefined | null | (() => HTMLElement);
/**
* When present, it specifies that the component should automatically get focus on load.
* @defaultValue false
Expand Down
4 changes: 3 additions & 1 deletion components/lib/calendar/Calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -1534,7 +1534,9 @@ export const Calendar = React.memo(
};

const appendDisabled = () => {
return props.appendTo === 'self' || props.inline;
const appendTo = props.appendTo || (context && context.appendTo) || PrimeReact.appendTo;

return appendTo === 'self' || props.inline;
};

const alignOverlay = () => {
Expand Down
2 changes: 1 addition & 1 deletion components/lib/calendar/calendar.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ interface CalendarBaseProps {
* DOM element instance where the overlay panel should be mounted. Valid values are any DOM Element and "self". The "self" value is used to render a component where it is located.
* @defaultValue document.body
*/
appendTo?: 'self' | HTMLElement | undefined | null;
appendTo?: 'self' | HTMLElement | undefined | null | (() => HTMLElement);
/**
* When present, it specifies that the component should automatically get focus on load.
* @defaultValue false
Expand Down
2 changes: 1 addition & 1 deletion components/lib/cascadeselect/cascadeselect.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ export interface CascadeSelectProps extends Omit<React.DetailedHTMLProps<React.I
* DOM element instance where the overlay panel should be mounted. Valid values are any DOM Element and "self". The "self" value is used to render a component where it is located.
* @defaultValue document.body
*/
appendTo?: 'self' | HTMLElement | undefined | null;
appendTo?: 'self' | HTMLElement | undefined | null | (() => HTMLElement);
/**
* The properties of CSSTransition can be customized, except for "nodeRef" and "in" properties.
* @type {CSSTransitionProps}
Expand Down
2 changes: 1 addition & 1 deletion components/lib/colorpicker/colorpicker.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export interface ColorPickerProps extends Omit<React.DetailedHTMLProps<React.Inp
* DOM element instance where the overlay panel should be mounted. Valid values are any DOM Element and "self". The "self" value is used to render a component where it is located.
* @defaultValue document.body
*/
appendTo?: 'self' | HTMLElement | undefined | null;
appendTo?: 'self' | HTMLElement | undefined | null | (() => HTMLElement);
/**
* When present, it specifies that the component should automatically get focus on load.
* @defaultValue false
Expand Down
2 changes: 1 addition & 1 deletion components/lib/confirmdialog/confirmdialog.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ export interface ConfirmDialogProps extends Omit<DialogProps, 'onHide' | 'footer
* DOM element instance where the overlay panel should be mounted. Valid values are any DOM Element and "self". The "self" value is used to render a component where it is located.
* @defaultValue document.body
*/
appendTo?: 'self' | HTMLElement | undefined | null;
appendTo?: 'self' | HTMLElement | undefined | null | (() => HTMLElement);
/**
* Style class of the element.
*/
Expand Down
2 changes: 1 addition & 1 deletion components/lib/confirmpopup/confirmpopup.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ export interface ConfirmPopupProps {
* DOM element instance where the overlay panel should be mounted. Valid values are any DOM Element and 'self'. The self value is used to render a component where it is located.
* @defaultValue document.body
*/
appendTo?: 'self' | HTMLElement | undefined | null;
appendTo?: 'self' | HTMLElement | undefined | null | (() => HTMLElement);
/**
* Enables to hide the popup when outside is clicked.
* @defaultValue true
Expand Down
2 changes: 1 addition & 1 deletion components/lib/contextmenu/contextmenu.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export interface ContextMenuProps extends Omit<React.DetailedHTMLProps<React.HTM
* DOM element instance where the overlay panel should be mounted. Valid values are any DOM Element and 'self'. The self value is used to render a component where it is located.
* @defaultValue document.body
*/
appendTo?: 'self' | HTMLElement | undefined | null;
appendTo?: 'self' | HTMLElement | undefined | null | (() => HTMLElement);
/**
* The properties of CSSTransition can be customized, except for "nodeRef" and "in" properties.
*/
Expand Down
2 changes: 1 addition & 1 deletion components/lib/datatable/datatable.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1221,7 +1221,7 @@ interface DataTableBaseProps<TValue extends DataTableValueArray> extends Omit<Re
* DOM element instance where the overlay panel should be mounted. Valid values are any DOM Element and 'self'. The self value is used to render a component where it is located.
* @defaultValue document.body
*/
paginatorDropdownAppendTo?: 'self' | HTMLElement | null | undefined;
paginatorDropdownAppendTo?: 'self' | HTMLElement | null | undefined | (() => HTMLElement);
/**
* Content for the left side of the paginator.
*/
Expand Down
2 changes: 1 addition & 1 deletion components/lib/dataview/dataview.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ export interface DataViewProps extends Omit<React.DetailedHTMLProps<React.HTMLAt
* DOM element instance where the overlay panel should be mounted. Valid values are any DOM Element and 'self'. The self value is used to render a component where it is located.
* @defaultValue document.body
*/
paginatorDropdownAppendTo?: 'self' | HTMLElement | undefined | null;
paginatorDropdownAppendTo?: 'self' | HTMLElement | undefined | null | (() => HTMLElement);
/**
* Array of integer values to display inside rows per page dropdown.
*/
Expand Down
2 changes: 1 addition & 1 deletion components/lib/dialog/dialog.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export interface DialogProps {
* DOM element instance where the overlay panel should be mounted. Valid values are any DOM Element and 'self'. The self value is used to render a component where it is located.
* @defaultValue document.body
*/
appendTo?: 'self' | HTMLElement | undefined | null;
appendTo?: 'self' | HTMLElement | undefined | null | (() => HTMLElement);
/**
* Defines a string that labels the close icon.
*/
Expand Down
2 changes: 1 addition & 1 deletion components/lib/dropdown/dropdown.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ export interface DropdownProps extends Omit<React.DetailedHTMLProps<React.InputH
* DOM element instance where the overlay panel should be mounted. Valid values are any DOM Element and "self". The "self" value is used to render a component where it is located.
* @defaultValue document.body
*/
appendTo?: 'self' | HTMLElement | undefined | null;
appendTo?: 'self' | HTMLElement | undefined | null | (() => HTMLElement);
/**
* Used to define a string that labels the component.
*/
Expand Down
2 changes: 1 addition & 1 deletion components/lib/menu/menu.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export interface MenuProps extends Omit<React.DetailedHTMLProps<React.HTMLAttrib
* DOM element instance where the overlay panel should be mounted. Valid values are any DOM Element and 'self'. The self value is used to render a component where it is located.
* @defaultValue document.body
*/
appendTo?: 'self' | HTMLElement | null | undefined;
appendTo?: 'self' | HTMLElement | null | undefined | (() => HTMLElement);
/**
* The properties of CSSTransition can be customized, except for "nodeRef" and "in" properties.
* @type {CSSTransitionProps}
Expand Down
2 changes: 1 addition & 1 deletion components/lib/multiselect/multiselect.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ export interface MultiSelectProps extends Omit<React.DetailedHTMLProps<React.Inp
* DOM element instance where the overlay panel should be mounted. Valid values are any DOM Element and 'self'. The self value is used to render a component where it is located.
* @defaultValue document.body
*/
appendTo?: 'self' | HTMLElement | undefined | null;
appendTo?: 'self' | HTMLElement | undefined | null | (() => HTMLElement);
/**
* Establishes relationships between the component and label(s) where its value should be one or more element IDs.
*/
Expand Down
2 changes: 1 addition & 1 deletion components/lib/overlaypanel/overlaypanel.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export interface OverlayPanelProps extends Omit<React.DetailedHTMLProps<React.HT
* DOM element instance where the overlay panel should be mounted. Valid values are any DOM Element and 'self'. The self value is used to render a component where it is located.
* @defaultValue document.body
*/
appendTo?: 'self' | HTMLElement | undefined | null;
appendTo?: 'self' | HTMLElement | undefined | null | (() => HTMLElement);
/**
* Aria label of the close icon.
* @defaultValue close
Expand Down
4 changes: 2 additions & 2 deletions components/lib/paginator/paginator.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ interface PaginatorRowsPerPageDropdownOptions {
/**
* DOM element instance where the overlay panel should be mounted. Valid values are any DOM Element and "self". The "self" value is used to render a component where it is located.
*/
appendTo: 'self' | HTMLElement | null | undefined;
appendTo: 'self' | HTMLElement | null | undefined | (() => HTMLElement);
/**
* The current page number.
*/
Expand Down Expand Up @@ -610,7 +610,7 @@ export interface PaginatorProps extends Omit<React.DetailedHTMLProps<React.HTMLA
* DOM element instance where the overlay panel should be mounted. Valid values are any DOM Element and 'self'. The self value is used to render a component where it is located.
* @defaultValue document.body
*/
dropdownAppendTo?: 'self' | HTMLElement | null | undefined;
dropdownAppendTo?: 'self' | HTMLElement | null | undefined | (() => HTMLElement);
/**
* Callback to invoke when page changes, the event object contains information about the new state.
* @param {PaginatorPageChangeEvent} event - Custom page change event.
Expand Down
2 changes: 1 addition & 1 deletion components/lib/password/password.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ export interface PasswordProps extends Omit<React.DetailedHTMLProps<React.InputH
* DOM element instance where the overlay panel should be mounted. Valid values are any DOM Element and 'self'. The self value is used to render a component where it is located.
* @defaultValue document.body
*/
appendTo?: 'self' | HTMLElement | undefined | null;
appendTo?: 'self' | HTMLElement | undefined | null | (() => HTMLElement);
/**
* Template of panel header if "feedback" is enabled.
*/
Expand Down
12 changes: 10 additions & 2 deletions components/lib/portal/Portal.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';
import ReactDOM from 'react-dom';
import PrimeReact, { PrimeReactContext } from '../api/Api';
import { useMountEffect, useUnmountEffect, useUpdateEffect } from '../hooks/Hooks';
import { DomHandler } from '../utils/Utils';
import { DomHandler, ObjectUtils } from '../utils/Utils';
import { PortalBase } from './PortalBase';

export const Portal = React.memo((inProps) => {
Expand All @@ -29,7 +29,15 @@ export const Portal = React.memo((inProps) => {
const element = props.element || props.children;

if (element && mountedState) {
const appendTo = props.appendTo || (context && context.appendTo) || PrimeReact.appendTo || document.body;
let appendTo = props.appendTo || (context && context.appendTo) || PrimeReact.appendTo;

if (ObjectUtils.isFunction(appendTo)) {
appendTo = appendTo();
}

if (!appendTo) {
appendTo = document.body;
}

return appendTo === 'self' ? element : ReactDOM.createPortal(element, appendTo);
}
Expand Down
2 changes: 1 addition & 1 deletion components/lib/sidebar/sidebar.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export interface SidebarProps extends Omit<React.DetailedHTMLProps<React.HTMLAtt
* DOM element instance where the overlay panel should be mounted. Valid values are any DOM Element and self. The self value is used to render a component where it is located.
* @defaultValue document.body
*/
appendTo?: 'self' | HTMLElement | null | undefined;
appendTo?: 'self' | HTMLElement | null | undefined | (() => HTMLElement);
/**
* The properties of CSSTransition can be customized, except for "nodeRef" and "in" properties.
* @type {CSSTransitionProps}
Expand Down
2 changes: 1 addition & 1 deletion components/lib/slidemenu/slidemenu.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export interface SlideMenuProps extends Omit<React.DetailedHTMLProps<React.HTMLA
* DOM element instance where the overlay panel should be mounted. Valid values are any DOM Element and 'self'. The self value is used to render a component where it is located.
* @defaultValue document.body
*/
appendTo?: 'self' | HTMLElement | undefined | null;
appendTo?: 'self' | HTMLElement | undefined | null | (() => HTMLElement);
/**
* Whether to automatically manage layering.
* @defaultValue true
Expand Down
2 changes: 1 addition & 1 deletion components/lib/splitbutton/splitbutton.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ export interface SplitButtonProps extends Omit<React.DetailedHTMLProps<React.HTM
* DOM element instance where the overlay panel should be mounted. Valid values are any DOM Element and 'self'. The self value is used to render a component where it is located.
* @defaultValue document.body
*/
appendTo?: 'self' | HTMLElement | null | undefined;
appendTo?: 'self' | HTMLElement | null | undefined | (() => HTMLElement);
/**
* Content of the tooltip.
*/
Expand Down
2 changes: 1 addition & 1 deletion components/lib/tieredmenu/tieredmenu.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export interface TieredMenuProps extends Omit<React.DetailedHTMLProps<React.HTML
* DOM element instance where the overlay panel should be mounted. Valid values are any DOM Element and 'self'. The self value is used to render a component where it is located.
* @defaultValue document.body
*/
appendTo?: 'self' | HTMLElement | null | undefined;
appendTo?: 'self' | HTMLElement | null | undefined | (() => HTMLElement);
/**
* The properties of CSSTransition can be customized, except for "nodeRef" and "in" properties.
* @type {CSSTransitionProps}
Expand Down
2 changes: 1 addition & 1 deletion components/lib/toast/toast.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ export interface ToastProps extends Omit<React.DetailedHTMLProps<React.HTMLAttri
* DOM element instance where the component should be mounted. Valid values are any DOM Element and 'self'. The self value is used to render a component where it is located.
* @defaultValue self
*/
appendTo?: 'self' | HTMLElement | null | undefined;
appendTo?: 'self' | HTMLElement | null | undefined | (() => HTMLElement);
/**
* Callback to invoke when an active tab is collapsed by clicking on the header.
* @param {ToastMessage} message - Clicked message
Expand Down
2 changes: 1 addition & 1 deletion components/lib/tooltip/tooltipoptions.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export interface TooltipOptions {
* DOM element instance where the overlay panel should be mounted. Valid values are any DOM Element and 'self'. The self value is used to render a component where it is located.
* @defaultValue document.body
*/
appendTo?: 'self' | HTMLElement | null | undefined;
appendTo?: 'self' | HTMLElement | null | undefined | (() => HTMLElement);
/**
* Defines which position on the target element to align the positioned tooltip.
*/
Expand Down
2 changes: 1 addition & 1 deletion components/lib/treeselect/treeselect.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ export interface TreeSelectProps extends Omit<React.DetailedHTMLProps<React.Inpu
* DOM element instance where the overlay panel should be mounted. Valid values are any DOM Element and 'self'. The self value is used to render a component where it is located.
* @defaultValue document.body
*/
appendTo?: 'self' | HTMLElement | undefined | null;
appendTo?: 'self' | HTMLElement | undefined | null | (() => HTMLElement);
/**
* Used to define a string that labels the component.
*/
Expand Down
2 changes: 1 addition & 1 deletion components/lib/treetable/treetable.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@ export interface TreeTableProps extends Omit<React.DetailedHTMLProps<React.Input
* DOM element instance where the overlay panel should be mounted. Valid values are any DOM Element and 'self'. The self value is used to render a component where it is located.
* @defaultValue document.body
*/
paginatorDropdownAppendTo?: 'self' | HTMLElement | undefined | null;
paginatorDropdownAppendTo?: 'self' | HTMLElement | undefined | null | (() => HTMLElement);
/**
* Content for the left side of the paginator.
*/
Expand Down

0 comments on commit 53df7c9

Please sign in to comment.