Skip to content

Commit

Permalink
[PLA-11322] Aria Combobox popover should not flip by default
Browse files Browse the repository at this point in the history
Change-Id: Iac08a209bac9bbfb91bc34ea8930d0bc6def928a
GitOrigin-RevId: c2c04319232edcc42df74af85c3613654759827b
  • Loading branch information
sarahsga authored and actions-user committed Oct 23, 2024
1 parent eb1e687 commit 3cc72b6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
4 changes: 3 additions & 1 deletion plasmicpkgs/react-aria/src/registerComboBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ export function BaseComboBox(props: BaseComboboxProps) {

return (
<ComboBox {...rest}>
<PlasmicPopoverContext.Provider value={{ isOpen }}>
<PlasmicPopoverContext.Provider
value={{ isOpen, defaultShouldFlip: false }}
>
<PlasmicListBoxContext.Provider
value={{
idManager,
Expand Down
17 changes: 8 additions & 9 deletions plasmicpkgs/react-aria/src/registerPopover.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { PlasmicElement, usePlasmicCanvasContext } from "@plasmicapp/host";
import { mergeProps } from "@react-aria/utils";
import React from "react";
import { Popover, PopoverContext, SelectContext } from "react-aria-components";
import { Popover, PopoverContext } from "react-aria-components";
import { PlasmicPopoverContext } from "./contexts";
import {
CodeComponentMetaOverrides,
Expand All @@ -20,22 +20,21 @@ export interface BasePopoverProps
HasControlContextData<PopoverControlContextData> {
className?: string;
resetClassName?: string;
defaultShouldFlip?: boolean;
}

export function BasePopover(props: BasePopoverProps) {
const { resetClassName, setControlContextData, ...restProps } = props;
const isStandalone = !React.useContext(PopoverContext);
const context = React.useContext(PlasmicPopoverContext);
const isInsideSelect = !!React.useContext(SelectContext);
const triggerRef = React.useRef<any>(null);
const isEditMode = !!usePlasmicCanvasContext();

// Select/Combobox popovers should not flip by default
const defaultShouldFlip = isInsideSelect ? false : true;

const mergedProps = mergeProps(
{ shouldFlip: defaultShouldFlip },
context,
{
isOpen: context?.isOpen,
shouldFlip: context?.defaultShouldFlip,
},
/**
* isNonModal: Whether the popover is non-modal, i.e. elements outside the popover may be interacted with by assistive technologies. *
*
Expand All @@ -55,7 +54,7 @@ export function BasePopover(props: BasePopoverProps) {
);

setControlContextData?.({
defaultShouldFlip,
defaultShouldFlip: context?.defaultShouldFlip ?? true,
});

return (
Expand Down Expand Up @@ -145,7 +144,7 @@ export function registerPopover(
type: "boolean",
description:
"Whether the element should flip its orientation (e.g. top to bottom or left to right) when there is insufficient room for it to render completely.",
defaultValueHint: (_props, ctx) => ctx?.defaultShouldFlip ?? true,
defaultValueHint: (_props, ctx) => ctx?.defaultShouldFlip,
},
placement: {
type: "choice",
Expand Down
4 changes: 3 additions & 1 deletion plasmicpkgs/react-aria/src/registerSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ export function BaseSelect(props: BaseSelectProps) {
isOpen={openProp}
{...extractPlasmicDataProps(props)}
>
<PlasmicPopoverContext.Provider value={{ isOpen: openProp }}>
<PlasmicPopoverContext.Provider
value={{ isOpen: openProp, defaultShouldFlip: false }}
>
<PlasmicListBoxContext.Provider
value={{
idManager,
Expand Down

0 comments on commit 3cc72b6

Please sign in to comment.