Skip to content

Commit e726dc8

Browse files
committed
Implement offset adjustments in Popover component
Added offsetX and offsetY props to Popover, allowing for custom positioning adjustments.
1 parent d1b89c7 commit e726dc8

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

src/scripts/AutoAlign.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ export type AutoAlignProps = {
168168
preventPortalize?: boolean;
169169
align?: Align;
170170
alignment?: RectangleAlignment;
171+
offsetX?: number;
172+
offsetY?: number;
171173
children: (props: AutoAlignInjectedProps) => ReactElement;
172174
};
173175

@@ -398,6 +400,8 @@ export const AutoAlign: FC<AutoAlignProps> = (props) => {
398400
preventPortalize,
399401
portalClassName: additionalPortalClassName,
400402
portalStyle: additionalPortalStyle = {},
403+
offsetX = 0,
404+
offsetY = 0,
401405
children,
402406
} = props;
403407
const {
@@ -419,6 +423,8 @@ export const AutoAlign: FC<AutoAlignProps> = (props) => {
419423
right: 0,
420424
},
421425
} = compSettings;
426+
const adjustedOffsetLeft = offsetLeft + offsetX;
427+
const adjustedOffsetTop = offsetTop + offsetY;
422428
if (typeof children !== 'function') {
423429
return React.isValidElement(children) ? children : <>{children}</>;
424430
}
@@ -429,9 +435,9 @@ export const AutoAlign: FC<AutoAlignProps> = (props) => {
429435
<div ref={elRef}>
430436
<RelativePortal
431437
fullWidth
432-
left={offsetLeft}
433-
right={-offsetLeft}
434-
top={offsetTop}
438+
left={adjustedOffsetLeft} // offsetXを適用
439+
right={-adjustedOffsetLeft}
440+
top={adjustedOffsetTop} // offsetYを適用
435441
onScroll={onScroll}
436442
component='div'
437443
className={classnames(portalClassName, additionalPortalClassName)}

src/scripts/Popover.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ export type PopoverProps = {
6868
theme?: PopoverTheme;
6969
tooltip?: boolean;
7070
bodyStyle?: CSSProperties;
71+
offsetX?: number;
72+
offsetY?: number;
7173
} & HTMLAttributes<HTMLDivElement>;
7274

7375
/**
@@ -131,7 +133,7 @@ export const PopoverInner = forwardRef<
131133
*
132134
*/
133135
export const Popover = forwardRef<HTMLDivElement, PopoverProps>(
134-
({ position, ...props }, ref) => {
136+
({ position, offsetX = 0, offsetY = 0, ...props }, ref) => {
135137
useInitComponentStyle();
136138

137139
const alignment: RectangleAlignment | undefined = position?.split('-') as
@@ -142,6 +144,8 @@ export const Popover = forwardRef<HTMLDivElement, PopoverProps>(
142144
triggerSelector='.slds-dropdown-trigger'
143145
alignmentStyle='popover'
144146
alignment={alignment}
147+
offsetX={offsetX}
148+
offsetY={offsetY}
145149
>
146150
{(injectedProps) => (
147151
<PopoverInner {...props} {...injectedProps} ref={ref} />

src/scripts/Tabs.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ const TooltipContent = (props: { children: ReactNode; icon: string }) => {
122122
hidden={isHideTooltip}
123123
tabIndex={-1}
124124
onBlur={onBlur}
125+
offsetX={-15}
125126
tooltip
126127
>
127128
{children}

0 commit comments

Comments
 (0)