Skip to content
This repository has been archived by the owner on Dec 6, 2022. It is now read-only.

Support responsive column widths #726

Merged
merged 7 commits into from
Feb 26, 2021
Merged

Support responsive column widths #726

merged 7 commits into from
Feb 26, 2021

Conversation

SiAdcock
Copy link
Contributor

@SiAdcock SiAdcock commented Feb 15, 2021

What is the purpose of this change?

It should be possible to specify the width of a column at various breakpoints, rather than the width being static across viewport widths.

It should also be possible to completely hide a column at certain breakpoints.

Fixes #701

What does this change?

  • Extend width API to accept an array of widths
  • A zero-width column should be hidden from the page

Screenshots

Responsive widths

<Columns>
	<Column width={[1 / 2, 1 / 4]}>
		<p>50% at mobile, 25% above tablet</p>
	</Column>
	<Column width={[1 / 2, 3 / 4]}>
		<p>50% width at mobile, 75% above tablet</p>
	</Column>
</Columns>

2021-02-16 11 27 09

Responsive hiding

<Columns>
	<Column width={[0, 1 / 4]}>
		<p>Not visible at mobile, 25% above tablet</p>
	</Column>
	<Column width={[1, 3 / 4]}>
		<p>100% at mobile, 75% above tablet</p>
	</Column>
</Columns>

2021-02-16 11 30 59

Checklist

Accessibility

Cross browser and device testing

  • Tested with touch screen device

Responsiveness

  • Tested at all breakpoints
  • Tested with with long text
  • Stretched to fill a wide container

Documentation

  • Full API surface area is documented in the README
  • Examples in Storybook

@probot-autolabeler probot-autolabeler bot added the Layout Changes to the layout components label Feb 15, 2021
@SiAdcock SiAdcock force-pushed the sa-responsive-column-width branch from 2cd12b9 to bc570c1 Compare February 15, 2021 12:07
@SiAdcock SiAdcock marked this pull request as ready for review February 16, 2021 12:15
@SiAdcock SiAdcock requested a review from a team February 16, 2021 12:15
Copy link
Member

@tomrf1 tomrf1 left a comment

Choose a reason for hiding this comment

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

looks great!

Comment on lines 8 to 15
& > div:nth-of-type(n + 2) {
margin-left: ${space[5]}px;
}
`;

const collapseBelowSpacing = css`
display: block;
& > * + * {
& > div:nth-of-type(n + 2) {

Choose a reason for hiding this comment

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

I don't quite follow this change. Would you mind explaining what the difference is?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh yes, I was messing around with something, but I didn't need it in the end. I'll restore the old way. Thanks for asking!

@SiAdcock SiAdcock force-pushed the sa-responsive-column-width branch from 8b6089f to cfd3986 Compare February 18, 2021 09:57
children,
...props
}: ColumnProps) => {
const Column = ({ width, cssOverrides, children, ...props }: ColumnProps) => {
Copy link
Member

Choose a reason for hiding this comment

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

if width no longer has a default value of 0, is this a breaking change?

Choose a reason for hiding this comment

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

If you were relying on the default before then I think you still get the same behaviour (due to these changes) but if you're explicitly passing 0 you will now get different behaviour so maybe it's a breaking change? Also, if you pass an empty array I don't think it's applying any styling. Maybe that should be the same as not passing a width?

Copy link
Contributor Author

@SiAdcock SiAdcock Feb 18, 2021

Choose a reason for hiding this comment

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

@jamie-lynch is correct, if you were explicitly passing width={0} before, the behaviour would have been the same as if you didn't pass a width (i.e. the column's width would be the remainder of container width shared between all zero-width columns). This behaviour was not documented. Arguably the behaviour is bizarre and unexpected, even a bug.

The new behaviour is to hide a column that has a 0 width. I think this is more intuitive.

Although this is technically a breaking change, I'm inclined not to treat it as such from a semver / release perspective. Nobody is currently relying on this behaviour. Let's close this loophole before people start relying on it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch with the empty array 🙏

I've updated the logic to treat an empty array the same as passing not passing a width. I hope that makes sense!

@SiAdcock SiAdcock force-pushed the sa-responsive-column-width branch from 6b254ff to 079cb9a Compare February 18, 2021 15:46
@SiAdcock SiAdcock merged commit e39792c into main Feb 26, 2021
@SiAdcock SiAdcock deleted the sa-responsive-column-width branch February 26, 2021 08:25
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Layout Changes to the layout components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Responsive column widths
4 participants