Skip to content

Commit

Permalink
[EuiFlyout] Fix broken push flyout behavior (#6764)
Browse files Browse the repository at this point in the history
* Fix focus trap scroll locking when disabled

* Harden scrollLock behavior on EuiFlyout

- push flyouts should still never set scrollLock to true

* changelog
  • Loading branch information
cee-chen authored May 9, 2023
1 parent 977f02d commit 5b62d9e
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 2 deletions.
13 changes: 13 additions & 0 deletions src/components/flyout/flyout.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,19 @@ describe('EuiFlyout', () => {
'euiFlyoutCloseButton'
);
});

it('does not focus trap or scrollLock for push flyouts', () => {
cy.mount(
<>
<div style={{ height: 2000 }}>Body scroll</div>
<Flyout type="push" pushMinBreakpoint="xs" size="100px" />
</>
);

cy.get('body').realClick({ position: 'topLeft' }).realPress('End'); // TODO: Use cypress-real-event's `realMouseWheel` API, whenever they release it
cy.wait(500); // Wait a tick to let scroll position update
cy.window().its('scrollY').should('not.equal', 0);
});
});

describe('Close behavior: standard', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/flyout/flyout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ export const EuiFlyout = forwardRef(
let flyout = (
<EuiFocusTrap
disabled={isPushed}
scrollLock={ownFocus}
scrollLock={hasOverlayMask}
clickOutsideDisables={!ownFocus}
onClickOutside={onClickOutside}
{...focusTrapProps}
Expand Down
13 changes: 13 additions & 0 deletions src/components/focus_trap/focus_trap.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,19 @@ describe('EuiFocusTrap', () => {
cy.window().its('scrollY').should('not.equal', 0);
});

it('does not scrollLock if the focus trap is disabled', () => {
cy.realMount(
<div style={{ height: 2000 }}>
<EuiFocusTrap disabled={true} scrollLock={true}>
Test
</EuiFocusTrap>
</div>
);

scrollSelector('body');
cy.window().its('scrollY').should('not.equal', 0);
});

it('prevents scrolling on the page body', () => {
cy.realMount(
<div style={{ height: 2000 }}>
Expand Down
2 changes: 1 addition & 1 deletion src/components/focus_trap/focus_trap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export class EuiFocusTrap extends Component<EuiFocusTrapProps, State> {
return (
<FocusOn {...focusOnProps}>
{children}
{scrollLock && <RemoveScrollBar gapMode={gapMode} />}
{!isDisabled && scrollLock && <RemoveScrollBar gapMode={gapMode} />}
</FocusOn>
);
}
Expand Down
3 changes: 3 additions & 0 deletions upcoming_changelogs/6764.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**Bug fixes**

- Fixed broken push `EuiFlyout` behavior

0 comments on commit 5b62d9e

Please sign in to comment.