Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dialog] Opening dialog overrides padding on the body element #610

Open
SiTaggart opened this issue Jun 9, 2020 · 7 comments
Open

[dialog] Opening dialog overrides padding on the body element #610

SiTaggart opened this issue Jun 9, 2020 · 7 comments
Labels
Help Wanted Extra attention is needed Type: Enhancement General improvements or suggestions

Comments

@SiTaggart
Copy link

🐛 Bug report

Current Behavior

When the dialog is open, react-remove-scroll via react-remove-scroll-bar, sets some css properties on the body. One of them is padding-top which is set to 0. We need to not do that for our page layout to not break.

We use a sticky masthead which the underlying content uses a padding top value on the body to not be obscured by the masthead.

When react-remove-scroll-bar removed the top padding, the top of the content is under the masthead and the bottom of the page jumps up.

https://share.getcloudapp.com/JruLNJ1j

Expected behavior

react-remove-scroll-bar does allow you to prevent or override some of these css properties. I should be able to pass dialog some control to prevent this from happening.

Suggested solution(s)

expose some react-remove-scroll-bar props to override the behavior.

Your environment

https://www.twilio.com/console/iot/supersim/network-access-profiles

@chaance
Copy link
Member

chaance commented Jun 11, 2020

I'm not sure how simply we can override this.

@theKashey Any suggestions on your end?

@chaance chaance added Status: Investigation Type: Enhancement General improvements or suggestions and removed Status: Consideration labels Jun 11, 2020
@theKashey
Copy link
Contributor

theKashey commented Jun 11, 2020

So that's a really hard part. I've spend quite a lot of time trying to understand that actually shall be done and "why", and at the end I didn't found an answer, that's why gapMode is still configurable.
Frankly speaking - all this voodoo magic is not required in case of allowRelative, but there are very good cases for allowRelative and it's enabled by default.
Probably adding logic "if !allowRelative don't touch padding-top", but that's would not end well.

And actually I have a simple suggestion - In order to have a gap between browser-top and the page content - don't use paddings on the body, but add a <div style="height:yourPadding"/> and it would result in the picture. Ie use additinal html tag instead of style on the body.

@SiTaggart
Copy link
Author

In order to have a gap between browser-top and the page content - don't use paddings on the body, but add a

and it would result in the picture. Ie use additinal html tag instead of style on the body.

Ordinarily this would be a fine solution. Something I would actually prefer honestly, but we are battling with previous folks decisions and almost zero confidence in being able to make that change to the application body styles.

Is there no way I can affect the behavior of the various remove-scroll packages from the dialog?

@theKashey
Copy link
Contributor

You can always add !important to your own styles or overspecifitify them in any other way. However that might shift your absolute positioned elements this time. Well, if you have them.

Another, probably good and working solution is to move existing styles "as-is" from the body to react root. Padding would be still "above your components" and effect in the same way, shifting your content a bit down, but it will not conflict with any other styles on the body.

@chaance chaance changed the title Opening dialog overrides padding on the body element [dialog] Opening dialog overrides padding on the body element Mar 30, 2021
@chaance chaance added Help Wanted Extra attention is needed and removed Status: Investigation labels Aug 3, 2021
@stale stale bot closed this as completed May 1, 2022
@ryparker
Copy link

ryparker commented May 11, 2022

Just sharing my workaround here in case anyone has a need to override this as well.

I passed dangerouslyBypassScrollLock into the DialogOverlay and used the useLockBodyScroll() hook from usehooks.com

i.g. implementation

const LoginDialog = (props: LoginDialogProps) => {
  const { onDismiss, ...delegated } = props;
  useLockBodyScroll();
  return (
    <DialogOverlay onDismiss={onDismiss} dangerouslyBypassScrollLock {...delegated}>
      <ContentBox aria-label="sign in dialog">
        <Title>Sign in</Title>
        <Button>Focusable</Button>
      </ContentBox>
    </DialogOverlay>
  );
};

@theKashey
Copy link
Contributor

Unfortunately useLockBodyScroll is not preventing scroll on Safari.
Wondering if this is related:

@chaance chaance reopened this May 18, 2022
@stale stale bot removed the Resolution: Stale label May 18, 2022
@ryparker
Copy link

ryparker commented May 19, 2022

@theKashey Good catch, I found a better solution from usehooks-ts.com. This works on Safari (desktop & mobile).

Here's a demo of it being used on https://congress.wiki/hr1-117

CleanShot.2022-05-19.at.09.57.32.mp4

Implementation:

const LoginDialog = (props: LoginDialogProps) => {
  const { isOpen, onDismiss, ...delegated } = props;

  // Lock body scroll when open
  const [locked, setLocked] = useLockedBody();
  useEffect(() => {
    setLocked(!!isOpen);
  }, [isOpen]);

  return (
    <DialogOverlay onDismiss={onDismiss} dangerouslyBypassScrollLock {...delegated}>
      <ContentBox aria-label="sign in dialog">
        <Title>Sign in</Title>
        <Button>Focusable</Button>
      </ContentBox>
    </DialogOverlay>
  );
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Help Wanted Extra attention is needed Type: Enhancement General improvements or suggestions
Projects
None yet
Development

No branches or pull requests

4 participants