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(ui-modal): make Modal's header non-sticky with small window height #1854

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ToMESSKa
Copy link
Contributor

@ToMESSKa ToMESSKa commented Jan 31, 2025

Closes: INSTUI-4391

ISSUE: Modal's header and footer are sitcky, so Modal.Body's content is hard to see and scroll on high zoom and narrow window, so it would be better if head become non-sticky according to the accessibility (A11y) team

TEST PLAN:

  • open the modal examples in the documentation preview.
  • zoom in to approximately 300%: the header should remain sticky.
  • zoom in further to around 400% without closing the modal: the header should now become non-sticky (i.e., it must scroll with the body)
  • repeat the previous steps, but instead of zooming in, resize the window to be narrower: there should be a breakpoint (around 320px) at which the header becomes non-sticky
  • (add additional text to the modal's body if the scrollbar does not appear

accessibility (A11y) team should review the component
also the exact breakpoint is still up for debate, I choose 20 rem now

@ToMESSKa ToMESSKa self-assigned this Jan 31, 2025
Copy link

github-actions bot commented Jan 31, 2025

PR Preview Action v1.6.0

🚀 View preview at
https://instructure.github.io/instructure-ui/pr-preview/pr-1854/

Built to branch gh-pages at 2025-02-07 15:03 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@@ -83,6 +83,7 @@ const generateStyle = (
borderBottomWidth: '0.0625rem',
borderBottomStyle: 'solid',
borderBottomColor: componentTheme.borderColor,
...(smallPortView ? { position: 'relative' } : {}),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I needed to add this because otherwise the close button starts scrolling with the text instead of staying in the Modal.Header

Comment on lines -156 to -161
return safeCloneElement(child, {
variant: variant,
overflow: (child?.props as { overflow: string })?.overflow || overflow
})
} else {
return child
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I moved this to the cloneChildWithProps function

Comment on lines +212 to +213
// Adds the <div> to the beginning of the filteredChildren array
if (headerAndBody.length > 0) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I needed to put the header and the body into the same element in order to be able scroll them together, so it results in some minor DOM change.

@ToMESSKa ToMESSKa requested a review from matyasf January 31, 2025 14:38
@ToMESSKa ToMESSKa marked this pull request as ready for review January 31, 2025 14:38
Copy link
Collaborator

@matyasf matyasf left a comment

Choose a reason for hiding this comment

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

I like the concept! There will be some issues with SSR, but thats an easy fix. After the a11y team agrees its good from me

@@ -86,7 +86,8 @@ class Modal extends Component<ModalProps, ModalState> {

this.state = {
transitioning: false,
open: props.open ?? false
open: props.open ?? false,
windowHeight: window.innerHeight
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should always put null checks to DOM APIs because they dont exist when the user uses SSR. You can use our canUseDOM function to check whether its rendered on the server. Its safe to use them in componentDidMount AFAIK (please double check!), but definitely not in a static method like here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I set windowHeight to 99999 in the state.(TypeScript didn't allow me not to define it). Also replaced a check with the canUseDOM.

@ToMESSKa ToMESSKa requested a review from balzss February 5, 2025 14:44
@ToMESSKa ToMESSKa force-pushed the INSTUI-4391_make_modal_nicer_on_400_zoom branch from 897784f to 232e1cb Compare February 7, 2025 14:57
@ToMESSKa ToMESSKa requested a review from matyasf February 7, 2025 15:12
Copy link
Collaborator

@matyasf matyasf left a comment

Choose a reason for hiding this comment

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

nice work!

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

Successfully merging this pull request may close these issues.

2 participants