Skip to content

Commit 4420a7a

Browse files
committed
[EuiPopover] Add new configurable repositionToCrossAxis prop
1 parent 1449880 commit 4420a7a

7 files changed

Lines changed: 61 additions & 1 deletion

File tree

src/components/basic_table/__snapshots__/collapsed_item_actions.test.tsx.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ exports[`CollapsedItemActions render with href and _target provided 1`] = `
4848
ownFocus={true}
4949
panelPaddingSize="none"
5050
popoverRef={[Function]}
51+
repositionToCrossAxis={true}
5152
>
5253
<EuiContextMenuPanel
5354
items={

src/components/datagrid/body/header/__snapshots__/data_grid_header_cell.test.tsx.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ exports[`EuiDataGridHeaderCell renders 1`] = `
5757
token="euiDataGridHeaderCell.actionsPopoverScreenReaderText"
5858
/>
5959
}
60+
repositionToCrossAxis={true}
6061
>
6162
<EuiListGroup
6263
data-test-subj="dataGridHeaderCellActionGroup-someColumn"

src/components/datagrid/controls/__snapshots__/display_selector.test.tsx.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ exports[`useDataGridDisplaySelector displaySelector renders a toolbar button/pop
3030
ownFocus={true}
3131
panelClassName="euiDataGrid__displayPopoverPanel"
3232
panelPaddingSize="s"
33+
repositionToCrossAxis={true}
3334
>
3435
<EuiI18n
3536
defaults={

src/components/popover/input_popover.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ export const EuiInputPopover: FunctionComponent<EuiInputPopoverProps> = ({
128128
return (
129129
<EuiPopover
130130
css={css(fullWidth ? undefined : logicalCSS('max-width', form.maxWidth))}
131+
repositionToCrossAxis={false}
131132
ownFocus={false}
132133
button={
133134
<EuiResizeObserver onResize={onResize}>

src/components/popover/popover.spec.tsx

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,4 +166,44 @@ describe('EuiPopover', () => {
166166
});
167167
});
168168
});
169+
170+
describe('repositionToCrossAxis', () => {
171+
beforeEach(() => {
172+
// Set a forced viewport with not enough room to render the popover vertically
173+
cy.viewport(500, 50);
174+
});
175+
176+
it('allows the popover to reposition to the cross/secondary axis if there is not enough room on the primary axis', () => {
177+
cy.mount(
178+
<PopoverComponent anchorPosition="downCenter">Test</PopoverComponent>
179+
);
180+
cy.get('[data-test-subj="togglePopover"]').click();
181+
182+
// Assert that the popover rendered horizontally and not vertically
183+
cy.get('[data-popover-panel]')
184+
.invoke('offset')
185+
.then(({ top, left }) => {
186+
expect(left).to.be.gt(top);
187+
});
188+
});
189+
190+
it('does not reposition to the cross axis if set to false', () => {
191+
cy.mount(
192+
<PopoverComponent
193+
anchorPosition="downCenter"
194+
repositionToCrossAxis={false}
195+
>
196+
Test
197+
</PopoverComponent>
198+
);
199+
cy.get('[data-test-subj="togglePopover"]').click();
200+
201+
// Assert that the popover vertically and not horizontally
202+
cy.get('[data-popover-panel]')
203+
.invoke('offset')
204+
.then(({ top, left }) => {
205+
expect(top).to.be.gt(left);
206+
});
207+
});
208+
});
169209
});

src/components/popover/popover.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,18 @@ export interface EuiPopoverProps extends PropsWithChildren, CommonProps {
163163
* an `EuiPopover` in a scrollable container, `repositionOnScroll` should be `true`
164164
*/
165165
repositionOnScroll?: boolean;
166+
/**
167+
* By default, popovers will attempt to position themselves along the initial
168+
* axis specified. If there is not enough room either vertically or horizontally
169+
* however, the popover will attempt to reposition itself along the secondary
170+
* cross axis if there is room there instead.
171+
*
172+
* If you do not not want this repositioning to occur (and it is acceptable for
173+
* the popover to appear offscreen), set this to false to disable this behavior.
174+
*
175+
* @default true
176+
*/
177+
repositionToCrossAxis?: boolean;
166178
/**
167179
* Must be set to true if using `EuiDragDropContext` within a popover,
168180
* otherwise your nested drag & drop will have incorrect positioning
@@ -281,6 +293,7 @@ export class EuiPopover extends Component<Props, State> {
281293
static defaultProps: Partial<PropsWithDefaults> = {
282294
isOpen: false,
283295
ownFocus: true,
296+
repositionToCrossAxis: true,
284297
anchorPosition: 'downCenter',
285298
panelPaddingSize: 'm',
286299
hasArrow: true,
@@ -517,7 +530,7 @@ export class EuiPopover extends Component<Props, State> {
517530
arrowBuffer: 10,
518531
},
519532
returnBoundingBox: this.props.attachToAnchor,
520-
allowCrossAxis: !this.props.attachToAnchor,
533+
allowCrossAxis: this.props.repositionToCrossAxis,
521534
buffer: this.props.buffer,
522535
});
523536

@@ -607,6 +620,7 @@ export class EuiPopover extends Component<Props, State> {
607620
hasArrow,
608621
arrowChildren,
609622
repositionOnScroll,
623+
repositionToCrossAxis,
610624
hasDragDrop,
611625
zIndex,
612626
attachToAnchor,

upcoming_changelogs/7211.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
- Updated `EuiPopover` with a new configurable `repositionToCrossAxis` prop
2+
13
**Bug fixes**
24

35
- Fixed `EuiPopover`'s missing animations on popover close

0 commit comments

Comments
 (0)