Skip to content
This repository has been archived by the owner on May 24, 2024. It is now read-only.

Modal #224

Merged
merged 43 commits into from
Apr 26, 2017
Merged

Modal #224

merged 43 commits into from
Apr 26, 2017

Conversation

Matt-Butler
Copy link
Contributor

Summary

Code Review for Modal component

I wanted to get this out so people can start looking at it. I am still going to add documentation to this code review.

I am also seeing this warning in the console when viewing nightwatch tests. I will fix that as well.

Warning: Exception thrown by hook while handling onSetChildren: Invariant Violation: Item must have been set

@cerner/terra

@bjankord
Copy link
Contributor

bjankord commented Apr 19, 2017

@Matt-Butler In regards to the warning thats being logged, do we know what code / commit is causing this. I'm curious how the CI tests pass if this is being logged, unless its a console.warn statement that is triggered instead of a console.error statement.

How is this error triggered?
Are we thinking React 15.5 is a hard dependency for modal?
Have you tested with React 15.5 to confirm this is warning doesn't occur?

Edit:

How is this error triggered?

Trigged by opening a modal and then clicking the browser back button or clicking a link to a new route. Seems the issue is related to modal code + react router updating routes.

Have you tested with React 15.5 to confirm this is warning doesn't occur?

Tested with React 15.5, the warning still occurs when following the steps above.

Warning: Exception thrown by hook while handling onSetChildren: Invariant Violation: Item must have been set
Invariant Violation: Item must have been set

We are also seeing a similar warning with react-datepicker. With webpack-dev-server running, navigate to the datepicker. Change the date and you will see a warning in the console.

**/
isOpened: PropTypes.bool,
/**
* String that labels the modal for screen readers
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this comment is out of date.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

@import '~terra-mixins';

.terra-Modal {
background-color: #fff;
Copy link
Contributor

Choose a reason for hiding this comment

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

overflow: hidden;
position: fixed;
right: 10px;
top: 10px;
Copy link
Contributor

Choose a reason for hiding this comment

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

Was a decision made about using px units vs rem? Will we just swing back through and use the new mixin for converting these when it's available?
#164

Copy link
Contributor

Choose a reason for hiding this comment

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

We should be using rem units. When the rem mixin is available we can start using pixel units in the mixin and output rems.

"classnames": "^2.2.5",
"focus-trap-react": "^3.0.2",
"terra-mixins": "^1.0.0",
"react-portal": "^3.0.0"
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this component need an explicit terra-base dependency?
#251

/**
* Content inside the modal dialog
**/
children: PropTypes.element.isRequired,
Copy link
Contributor

@StephenEsser StephenEsser Apr 21, 2017

Choose a reason for hiding this comment

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

Similar to how we standardized the height / width properties I think children type is also something we should standardize. ( with maybe the exception of restrictive element children of a specific component type )

I believe most components specify the child type as node so that any renderable object can be passed into children. I think it becomes a little confusing when some components can render anything while other components will only accept element types as children.


componentDidMount() {
// Disable background scrolling
document.body.style.overflow = 'hidden';
Copy link
Contributor

@StephenEsser StephenEsser Apr 21, 2017

Choose a reason for hiding this comment

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

Would the Overlay prevent any scroll events? Many Orion applications utilize a SlidePanel / fixed ContentPanel as a base component that manages its' own overflow, without the overlay I think these would still scroll. I think the current implementation has the full screen overlay prevent any scrolling.

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'm not sure I quite follow. Are you proposing that when the modal is active, content in the background can still scroll?

Also, the current implementation enforces that there is always an overlay when a modal is active.

Copy link
Contributor

@StephenEsser StephenEsser Apr 21, 2017

Choose a reason for hiding this comment

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

I think content can still scroll even if you set this on body because body is not the only element that can have an overflow set, so I don't think this is an effective way to disable scrolling. But the Overlay can stop scrolling, does that make any sense?


componentWillUnmount() {
// Enable background scrolling
document.body.style.overflow = null;
Copy link
Contributor

Choose a reason for hiding this comment

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

This could potentially cause some thrashing if the consuming application has styles set on the body

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 should only affect the overflow style property on the body. When do you think this would be an issue?

Copy link
Contributor

@StephenEsser StephenEsser Apr 21, 2017

Choose a reason for hiding this comment

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

I think this could cause unwanted side effects. As an example the base layout every Orion application uses currently has body overflow set to hidden. This will result in removing that style and potentially causing a lot of issues with the layout.

https://github.cerner.com/orion/orion-rails-layouts/blob/778b1c4973bfbeab416e228f66f71ab75c737d8e/app/views/orion/rails/layouts/_base.html.haml#L25

https://github.cerner.com/orion/orion-rails/blob/c26aa2eb622708549f70bcd84a9f95adf3713d7a/app/assets/stylesheets/orion/layouts/base.less#L15

import './ModalOverlay.scss';

const propTypes = {
classNameOverlay: PropTypes.string,
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a good reason to keep this as an explicit prop rather than just spreading custom props onto the overlay?

I think you're using className above to pass the class, and not actually using this prop.

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'm going to move the overlay class logic into overlay

@@ -0,0 +1,3 @@
# Themeable Variables

Copy link
Contributor

Choose a reason for hiding this comment

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

If there are no themeable variables, this file can be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed file

@import '~terra-mixins';

.terra-Modal {
background-color: $terra-white;
Copy link
Contributor

Choose a reason for hiding this comment

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

Use rem values for these pixel values.
With the 14px root font, 10px = 0.714rem. 5px = 0.357rem.

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 think we want to keep left, right, top, and bottom as 10px instead of rem. If the user updates the font size in their browser, we probably want the area around the modal dialog to stay consistent.
Large Font
largefont
Small Font
smallfont

Copy link
Contributor

Choose a reason for hiding this comment

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

Good point, yeah lets leave these position properties as PX units.

border-radius: 5px;
bottom: 10px;
display: block;
left: 10px;
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated to use mixin

outline: none;
overflow: hidden;
position: fixed;
right: 10px;
Copy link
Contributor

Choose a reason for hiding this comment

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

Update this to use to position-end mixin: Update this to use the position-start mixin: https://github.com/cerner/terra-core/tree/master/packages/terra-mixins/docs#terra-position-start--terra-position-end

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated to use mixin

@media screen and (min-width: 48em) {
&:not(.terra-Modal--fullscreen) {
bottom: auto;
box-shadow: 0 3px 7px rgba(0, 0, 0, 0.3);
Copy link
Contributor

Choose a reason for hiding this comment

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

These can stay as pixel values.

@Matt-Butler Matt-Butler merged commit 2e1fddb into master Apr 26, 2017
@Matt-Butler Matt-Butler deleted the modal branch April 26, 2017 17:42
This was referenced Apr 27, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants