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

fix(dialog-full-screen): prevent horizontal overflow due to a child Form with a sticky footer #6742

Merged
merged 3 commits into from
Jun 5, 2024

Conversation

Parsium
Copy link
Contributor

@Parsium Parsium commented May 22, 2024

closes #6719

Proposed behaviour

Ensure when DialogFullscreen is rendered without padding, and contains a wrapped sticky form:

const MyDialog = () => {
  const MyStickyForm = () => (
    <Form stickyFooter>Content</Form>
  );
  
  return (
    <DialogFullscreen open disableContentPadding title="title">
      <MyStickyForm/>
    </DialogFullscreen>
  );
}

that:

  • No padding nor margins are added to DialogFullscreen's content wrapper - which caused content to overflow horizontally.
  • The content wrapper does not clip any overflowing content and continues to delegate handling this to the child Form.

Current behaviour

When DialogFullscreen is rendered without padding, and contains a wrapped sticky form, content overflows horizontally and the vertical scrollbar is not visible:
Screenshot 2024-05-22 at 13 21 30

Checklist

  • Commits follow our style guide
  • Related issues linked in commit messages if required
  • Screenshots are included in the PR if useful
  • All themes are supported if required
  • Unit tests added or updated if required
  • Playwright automation tests added or updated if required
  • Storybook added or updated if required
  • Translations added or updated (including creating or amending translation keys table in storybook) if required
  • Typescript d.ts file added or updated if required
  • Related docs have been updated if required

QA

  • Tested in provided StackBlitz sandbox/Storybook
  • Add new Playwright test coverage if required
  • Carbon implementation matches Design System/designs
  • UI Tests GitHub check reviewed if required

Testing instructions

For comparing behaviour before and after these changes, please use the following demos when manually testing:

Demo of current behaviour:

Demo of bug

Demo of new behaviour:

  1. Open Storybook locally with npm start
  2. Open DialogFullscreen's test story "With Sticky Form"
  3. Open controls, set disableContentPadding prop to true
  4. Observe no horizontal scrollbar and that the vertical scrollbar is present again

@Parsium Parsium self-assigned this May 22, 2024
@Parsium Parsium changed the title Fe 6570/form scrollbar bug @Parsium fix(dialog-full-screen): prevent horizontal overflow due to a child Form with a sticky footer May 22, 2024
@Parsium Parsium changed the title @Parsium fix(dialog-full-screen): prevent horizontal overflow due to a child Form with a sticky footer fix(dialog-full-screen): prevent horizontal overflow due to a child Form with a sticky footer May 22, 2024
@Parsium
Copy link
Contributor Author

Parsium commented May 22, 2024

Note: This is a temporary fix for the reported bug.

I suggest revisiting the implementation of form modals in Carbon, as currently our modal components (namely Dialog, DialogFullScreen and Sidebar) are all coupled with forms to support sticky footers.

Removing this decoupling will make the component's code more maintainable by avoiding child iteration/CSS overrides. And allow consumers to compose the components more freely without worrying about side-effects, such as the original bug addressed in this PR. This would most likely be a breaking change.

I've raised a new ticket FE-6643 to address this.

Comment on lines -7 to -15
React.Children.toArray(children).some(
(child) =>
React.isValidElement(child) &&
(child.type as React.FunctionComponent)?.displayName ===
Form.displayName &&
child.props.stickyFooter
),
[children]
);
Copy link
Contributor Author

@Parsium Parsium May 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this hook iterates over children, only Forms that are passed as direct React nodes will be checked. This is why CSS styling has been used instead to account when a form is wrapped

Comment on lines +125 to +132
const hasStickyFooter = useMemo(
() =>
React.Children.toArray(children).some(
(child) =>
React.isValidElement<FormProps>(child) && child.props.stickyFooter
),
[children]
);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will need updating as well at a future date, since any wrapped Forms won't be recognised

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could use DOM querying here

const hasStickyFooter = () => {
  const form = ref.current?.querySelector("[data-component='form']");
  
  return form.classList.contains("sticky");
};

edleeks87
edleeks87 previously approved these changes May 23, 2024
Copy link
Contributor

@edleeks87 edleeks87 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM @Parsium, might be worth getting UX to review it as there's potentially some changes to the layout if they've rendered content above the form (not within). It's not great in master so I think these changes are fine imo (surely someone will have raised an issue by now if it wasn't) but still worth double checking

@Parsium Parsium marked this pull request as ready for review May 28, 2024 09:51
@Parsium Parsium requested review from a team as code owners May 28, 2024 09:51
@Parsium
Copy link
Contributor Author

Parsium commented May 28, 2024

LGTM @Parsium, might be worth getting UX to review it as there's potentially some changes to the layout if they've rendered content above the form (not within). It's not great in master so I think these changes are fine imo (surely someone will have raised an issue by now if it wasn't) but still worth double checking

@harpalsingh for context, currently adding content above or below the sticky footer form (not within it) will break the layout:

Screenshot of broken scrollbar layout

This is evident in master as well, and fixing it will require significant refactoring of how this pattern is implemented.

No consumer has raised an issue for this, as we assume most are currently adding additional content within the form rather than above/below it, but are you happy for us to address it later?

@harpalsingh
Copy link
Member

@Parsium I've approved the review, but I do feel we should eventually look at the issue if the content is added above/below the form.

@Parsium Parsium dismissed stale reviews from mihai-albu-sage and edleeks87 via f7af444 June 4, 2024 09:16
@Parsium Parsium force-pushed the FE-6570/form-scrollbar-bug branch 2 times, most recently from f7af444 to 7b012a3 Compare June 4, 2024 09:36
@Parsium
Copy link
Contributor Author

Parsium commented Jun 4, 2024

@Parsium I've approved the review, but I do feel we should eventually look at the issue if the content is added above/below the form.

Thanks @harpalsingh, raised this as FE-6643

@Parsium Parsium force-pushed the FE-6570/form-scrollbar-bug branch from 7b012a3 to efd0884 Compare June 4, 2024 15:05
@Parsium Parsium merged commit 9a38bbe into master Jun 5, 2024
21 checks passed
@Parsium Parsium deleted the FE-6570/form-scrollbar-bug branch June 5, 2024 08:58
@carbonci
Copy link
Collaborator

carbonci commented Jun 5, 2024

🎉 This PR is included in version 136.0.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

Form in a Dialog Fullscreen with disableContentPadding
6 participants