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

fix(1980): add portal option to DatePicker, MenuPopover, and Popover components #1991

Merged
merged 1 commit into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion packages/shoreline/src/components/date-picker/date-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ import { useStore } from '@vtex/shoreline-utils'
* <DatePicker />
*/
export function DatePicker<T extends DateValue>(props: DatePickerProps<T>) {
const { className, id: defaultId, error: defaultError, ...domProps } = props
const {
className,
id: defaultId,
error: defaultError,
portal = true,
...domProps
} = props
const state = useDatePickerState(domProps)
const ref = useRef(null)
const anchorRef = useRef<HTMLDivElement>(null)
Expand Down Expand Up @@ -68,6 +74,7 @@ export function DatePicker<T extends DateValue>(props: DatePickerProps<T>) {
</div>
</div>
<Popover
portal={portal}
getAnchorRect={() => {
if (anchorRef?.current) {
return anchorRef.current.getBoundingClientRect()
Expand All @@ -92,6 +99,11 @@ export interface DatePickerOptions<T extends DateValue>
* Wether has error
*/
error?: boolean
/**
* Should activate portal
* @default true
*/
portal?: boolean
}

export type DatePickerProps<T extends DateValue> = DatePickerOptions<T>
9 changes: 7 additions & 2 deletions packages/shoreline/src/components/menu/menu-popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import { Menu } from '@ariakit/react'
*/
export const MenuPopover = forwardRef<HTMLDivElement, MenuPopoverProps>(
function MenuPopover(props, ref) {
const { children, asChild = false, ...otherProps } = props
const { children, asChild = false, portal = true, ...otherProps } = props

return (
<Menu
data-sl-menu-popover
ref={ref}
render={asChild && (children as any)}
gutter={4}
portal
portal={portal}
{...otherProps}
>
{children}
Expand All @@ -31,6 +31,11 @@ export interface MenuPopoverOptions {
* @default false
*/
asChild?: boolean
/**
* Should activate portal
* @default true
*/
portal?: boolean
}

export type MenuPopoverProps = MenuPopoverOptions &
Expand Down
9 changes: 7 additions & 2 deletions packages/shoreline/src/components/popover/popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ import { Popover as BasePopover } from '@ariakit/react'
*/
export const Popover = forwardRef<HTMLDivElement, PopoverProps>(
function Popover(props, ref) {
const { children, asChild = false, ...otherProps } = props
const { children, asChild = false, portal = true, ...otherProps } = props

return (
<BasePopover
data-sl-popover
ref={ref}
render={asChild && (children as any)}
portal
portal={portal}
gutter={4}
{...otherProps}
>
Expand All @@ -38,6 +38,11 @@ export interface PopoverOptions extends Pick<BaseProps, 'getAnchorRect'> {
* @default false
*/
asChild?: boolean
/**
* Should activate portal
* @default true
*/
portal?: boolean
}

export type PopoverProps = PopoverOptions & ComponentPropsWithoutRef<'div'>