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

Create FormLayout component #93

Merged
merged 2 commits into from
Jun 5, 2020
Merged

Create FormLayout component #93

merged 2 commits into from
Jun 5, 2020

Conversation

adamkudrna
Copy link
Member

@adamkudrna adamkudrna commented Jun 2, 2020

  • Create FormLayout component and make form fields ready for it
  • Add support for React Fragments to CardList and FormLayout

Closes #44.

Vertical Form Layout

image

With FF grid inspector on:

image

Horizontal Form Layout

Firefox – Subgrid Solution (auto-sized column with labels)

https://caniuse.com/#feat=css-subgrid

image

With FF grid inspector on:

image

Webkit – Fallback Solution (fixed-width column with labels)

image

Edge Cases

Label width is limited to 50 % of available horizontal space.

⚠️ Maximum label width and text wrapping is not available for small input sizes. It seems to be technically impossible to have both fluid label and wrapping helper text without unwanted impact on design.

Snímek obrazovky 2020-06-02 v 12 20 43

Snímek obrazovky 2020-06-02 v 12 21 12

Snímek obrazovky 2020-06-02 v 12 20 20

@adamkudrna adamkudrna added this to the v0.31.0 milestone Jun 2, 2020
@adamkudrna adamkudrna self-assigned this Jun 2, 2020
@@ -19,7 +20,7 @@ const CardList = (props) => {
className={styles.root}
{...other}
>
{React.Children.map(children, (child) => {
{flattenChildren(children).map((child) => {
Copy link
Member Author

Choose a reason for hiding this comment

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

Fragments are not traversed with React.children.map() [1][2] so I'm using the react-keyed-flatten-children bundle to flatten the children to a one-dimensional array. This is necessary to be able to pass props to children of these layouts.

[1] https://reactjs.org/docs/react-api.html#reactchildrenmap
[2] reactjs/rfcs#61 (comment)

name="Vertical Form Layout"
component={(
<FormLayout>
<>
Copy link
Member Author

Choose a reason for hiding this comment

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

This is an example of React.Fragment that we need to be able to traverse for the Form Layout to work even with form fields nested in fragments.

@adamkudrna
Copy link
Member Author

Nobody noticed the tests were missing? Shame on you! 🙂

@adamkudrna
Copy link
Member Author

adamkudrna commented Jun 4, 2020

Updates:

  • I added option to define custom label width per instance.
  • Custom auto-width fallback is now also possible per instance.
  • I added fixed label width option and made it the default value — now when we support other options than auto it seems to be better to offer a default that works in all browsers.

Snímek obrazovky 2020-06-04 v 23 15 54

Fragments are not traversed with `React.children.map()` [1][2] so we are using the `react-keyed-flatten-children` bundle to flatten the children to a one-dimensional array. This is necessary to be able to pass props to children of these layouts.

[1] https://reactjs.org/docs/react-api.html#reactchildrenmap
[2] reactjs/rfcs#61 (comment)
@adamkudrna adamkudrna merged commit b8f8d36 into master Jun 5, 2020
@adamkudrna adamkudrna deleted the feature/44 branch June 5, 2020 10:18
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.

Better form layout
2 participants