Skip to content

Commit

Permalink
[docs] minor UX smoothing
Browse files Browse the repository at this point in the history
- make toggling the push flyout slightly less annoying/jumpy

- by re-scrolling/re-centering on the toggle button
  • Loading branch information
cee-chen committed Sep 30, 2023
1 parent e780de0 commit a632b08
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src-docs/src/views/flyout/flyout_push.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from 'react';
import React, { useState, MouseEvent } from 'react';

import {
EuiFlyout,
Expand Down Expand Up @@ -63,7 +63,25 @@ export default () => {
compressed
/>
<EuiSpacer size="m" />
<EuiButton onClick={() => setIsFlyoutVisible((visible) => !visible)}>
<EuiButton
onClick={(event: MouseEvent) => {
setIsFlyoutVisible((visible) => !visible);

// Minor UX smoothing - make sure the flyout toggle button stays anchored
// in the same spot in the user viewport once layout is done shifting
const button = event.target as HTMLButtonElement;
const initialTop = button.getBoundingClientRect().top;
setTimeout(() => {
const newTop = button.getBoundingClientRect().top;
const scrollDiff = newTop - initialTop;
window.scrollTo({
top: window.scrollY + scrollDiff,
left: window.scrollX,
behavior: 'smooth',
});
}, 50);
}}
>
Toggle pushed flyout
</EuiButton>
{flyout}
Expand Down

0 comments on commit a632b08

Please sign in to comment.