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

Avoiding placeholder collapse caused by flex siblings #439

Merged
merged 12 commits into from
Apr 16, 2018

Conversation

alexreardon
Copy link
Collaborator

@alexreardon alexreardon commented Apr 13, 2018

Change 1: placeholder

When a placeholder is placed, it can be collapsed by flex siblings as it might have a smaller 'width' property. By avoiding flexshrink and flexgrow we avoid visual jank.

Use case:

  • have multiple draggables side by side (horizontal list). They need to have a width property (say '200px')
  • the draggables are flex siblings
  • resize the screen so that the items need to shrink a little (so they are now ~150px)
  • When you start a drag we give the placeholder the current size of 150px
  • The placeholder is then collapsed as it has a lower base width (150px) then the other flex children which have 200px.

By opting out of flex-grow and flex-shrink on the placeholder we avoid the placeholder being pushed or pulled by flex siblings

Change 2: internal box model cleanup

I have gone deep and improved the internal box model to be more accurate

@alexreardon alexreardon requested a review from petegleeson April 13, 2018 03:47
@alexreardon alexreardon changed the title adding extra placeholder love Avoiding placeholder collapse caused by flex siblings Apr 13, 2018
// Maps to the CSS box model
// https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Box_Model/Introduction_to_the_CSS_box_model
/*
# The CSS box model
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is really the core change. Being more aware of the box model.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Previously we where incorrectly labelling paddingBox as borderBox. Additionally, the contentBox for a Droppable was not correctly excluding borders. It was only subtracting padding which is not enough to get to the content box.

CSS!

// Maps to the CSS box model
// https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Box_Model/Introduction_to_the_CSS_box_model
/*
# The CSS box model
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Previously we where incorrectly labelling paddingBox as borderBox. Additionally, the contentBox for a Droppable was not correctly excluding borders. It was only subtracting padding which is not enough to get to the content box.

CSS!

boxSizing: 'border-box',
display,
// Avoiding the collapsing or growing of this element when pushed by flex child siblings.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Here is the placeholder fix

@alexreardon
Copy link
Collaborator Author

The box model changes fixes a bug where there incorrect movement into an empty droppable that has a border

Before

border-bug-before

After

border-bug-after

// We have already taken a snapshot the current dimensions we do not want this element
// to recalculate its dimensions
// It is okay for these properties to be applied on elements that are not flex children
flexShrink: '0',
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is the fix to the first issue: avoiding dynamic changes to the placeholder if it is a flex sibling

@@ -272,8 +270,18 @@ export default class DroppableDimensionPublisher extends Component<Props> {
bottom: parseInt(style.paddingBottom, 10),
left: parseInt(style.paddingLeft, 10),
};
const border: Spacing = {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

droppable contentBox now correctly accounting for borders

@alexreardon
Copy link
Collaborator Author

/cc @jaredcrowe as we have talked about this problem space before

@alexreardon alexreardon merged commit 66ab11d into master Apr 16, 2018
@alexreardon alexreardon deleted the placeholder-fix branch April 16, 2018 00:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant