Skip to content

Commit e93493f

Browse files
committed
Add data-crossplacement
1 parent 1dd65ff commit e93493f

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

packages/@react-aria/overlays/src/calculatePosition.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ export interface PositionResult {
6868
arrowOffsetLeft?: number,
6969
arrowOffsetTop?: number,
7070
maxHeight: number,
71-
placement: PlacementAxis
71+
placement: PlacementAxis,
72+
crossPlacement: PlacementAxis
7273
}
7374

7475
const AXIS = {
@@ -441,7 +442,8 @@ export function calculatePositionInternal(
441442
maxHeight: maxHeight,
442443
arrowOffsetLeft: arrowPosition.left,
443444
arrowOffsetTop: arrowPosition.top,
444-
placement: placementInfo.placement
445+
placement: placementInfo.placement,
446+
crossPlacement: placementInfo.crossPlacement
445447
};
446448
}
447449

packages/@react-aria/overlays/src/useOverlayPosition.ts

+3
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ export interface PositionAria {
6868
arrowProps: DOMAttributes,
6969
/** Placement of the overlay with respect to the overlay trigger. */
7070
placement: PlacementAxis | null,
71+
/** Cross placement of the overlay with respect to the overlay trigger. */
72+
crossPlacement: PlacementAxis | null,
7173
/** Updates the position of the overlay. */
7274
updatePosition(): void
7375
}
@@ -287,6 +289,7 @@ export function useOverlayPosition(props: AriaPositionProps): PositionAria {
287289
}
288290
},
289291
placement: position?.placement ?? null,
292+
crossPlacement: position?.crossPlacement ?? null,
290293
arrowProps: {
291294
'aria-hidden': 'true',
292295
role: 'presentation',

packages/@react-aria/overlays/src/usePopover.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ export interface PopoverAria {
6969
/** Props to apply to the underlay element, if any. */
7070
underlayProps: DOMAttributes,
7171
/** Placement of the popover with respect to the trigger. */
72-
placement: PlacementAxis | null
72+
placement: PlacementAxis | null,
73+
/** Cross placement of the popover with respect to the trigger. */
74+
crossPlacement: PlacementAxis | null
7375
}
7476

7577
/**
@@ -101,7 +103,7 @@ export function usePopover(props: AriaPopoverProps, state: OverlayTriggerState):
101103
groupRef ?? popoverRef
102104
);
103105

104-
let {overlayProps: positionProps, arrowProps, placement} = useOverlayPosition({
106+
let {overlayProps: positionProps, arrowProps, placement, crossPlacement} = useOverlayPosition({
105107
...otherProps,
106108
targetRef: triggerRef,
107109
overlayRef: popoverRef,
@@ -127,6 +129,7 @@ export function usePopover(props: AriaPopoverProps, state: OverlayTriggerState):
127129
popoverProps: mergeProps(overlayProps, positionProps),
128130
arrowProps,
129131
underlayProps,
130-
placement
132+
placement,
133+
crossPlacement
131134
};
132135
}

packages/react-aria-components/src/Popover.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ function PopoverInner({state, isExiting, UNSTABLE_portalContainer, ...props}: Po
151151
}
152152
}, [state.isOpen, arrowRef]);
153153

154-
let {popoverProps, underlayProps, arrowProps, placement} = usePopover({
154+
let {popoverProps, underlayProps, arrowProps, placement, crossPlacement} = usePopover({
155155
...props,
156156
offset: props.offset ?? 8,
157157
arrowSize: arrowWidth,
@@ -205,6 +205,7 @@ function PopoverInner({state, isExiting, UNSTABLE_portalContainer, ...props}: Po
205205
dir={props.dir}
206206
data-trigger={props.trigger}
207207
data-placement={placement}
208+
data-crossplacement={crossPlacement}
208209
data-entering={isEntering || undefined}
209210
data-exiting={isExiting || undefined}>
210211
{!props.isNonModal && <DismissButton onDismiss={state.close} />}

0 commit comments

Comments
 (0)