amplify-ui icon indicating copy to clipboard operation
amplify-ui copied to clipboard

Flex props do not work for components

Open hein-j opened this issue 3 years ago • 1 comments

Before creating a new issue, please confirm:

On which framework/platform are you having an issue?

React

Which UI component?

Other

How is your app built?

Create React App

What browsers are you seeing the problem on?

Chrome

Please describe your bug.

If I put my TextField inside a Flex component and set the grow to 1, the property does not get set in the CSS. Same goes for other components like SelectField, etc.

What's the expected behaviour?

According to the docs, grow, flex, and other flex properties should work for all UI React components.

Help us reproduce the bug!

  1. Create jsx like so:
      <Flex direction={'row'} backgroundColor={'pink'}>
        <TextField label={'Label!'} grow={1}/>
      </Flex>
  1. See that the TextField does not get stretched out.
  2. See that the CSS is not applied

Code Snippet

No response

Additional information and screenshots

Actual: Screen Shot 2022-09-20 at 11 56 39 Screen Shot 2022-09-20 at 11 56 14

Expected: Screen Shot 2022-09-20 at 11 56 57 Screen Shot 2022-09-20 at 11 56 53

hein-j avatar Sep 20 '22 18:09 hein-j

Thank you for your detailed issue report @hein-j. I was able to reproduce this bug and traced it to the flex-grow style not being properly applied to the <input> container in the <TextField> component. We'll prioritize this and work on getting a fix out as soon as possible!

slaymance avatar Sep 21 '22 00:09 slaymance

This fix will be part of the next major release of the @aws-amplify/ui-react package. You can track the progress of that release's work here: #2636

slaymance avatar Sep 23 '22 18:09 slaymance

The style props being applied is one thing, which we are changing in the next major version in the above PR. To fix the problem of TextFields not stretching, you don't need grow on the TextField itself. Remove flex={'grow'} and direction={'row'} from the example code.

CleanShot 2022-09-23 at 15 54 23@2x

https://stackblitz.com/edit/nextjs-xegiy8?file=pages/index.js

dbanksdesign avatar Sep 23 '22 22:09 dbanksdesign

@slaymance, Thank you for working on the fix!

@dbanksdesign, Thanks for the suggestion. The issue is precisely that it doesn't work when the containing Flex has direction=row. If a customer wants to put 2 TextFields in one row and get them to stretch with the parent Flex, they cannot.

hein-j avatar Sep 23 '22 23:09 hein-j

Ah I see the issue now. Yea we are applying the grow property onto the input instead of the wrapper element. A workaround before the next major version would be:

CleanShot 2022-09-23 at 16 40 24@2x

dbanksdesign avatar Sep 23 '22 23:09 dbanksdesign

Ohh I didn't think of that. Good to know.

hein-j avatar Sep 24 '22 00:09 hein-j

@dbanksdesign @slaymance We were going to open another issue as a P1 on display=none not completely working on certain components. I'm guessing it's addressed by this change, but just wanted to confirm. If not, I'll open a separate issue:

Screen Shot 2022-09-23 at 17 23 10 Screen Shot 2022-09-23 at 17 23 06

hein-j avatar Sep 24 '22 00:09 hein-j

@hein-j Yes, that will be addressed together along with the change

zchenwei avatar Dec 05 '22 19:12 zchenwei