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

fix(ui-text-input): fix long before elements overflowing in TextInput, Select,SimpleSelect #1809

Merged
merged 1 commit into from
Dec 6, 2024

Conversation

matyasf
Copy link
Collaborator

@matyasf matyasf commented Dec 3, 2024

Closes: INSTUI-4344

When adding lots of elements like Tags it was overflowing the input field, this commit fixes it

This bug was introduced with #1696 when we added a Flex layout without wrap.

TEST PLAN:
Add lots of elements to renderBeforeInput to Select,SimpleSelect,TextInput. They should wrap not overflow

@matyasf matyasf requested a review from ToMESSKa December 3, 2024 14:47
@matyasf matyasf self-assigned this Dec 3, 2024
@matyasf matyasf requested a review from balzss December 3, 2024 14:48
Copy link

github-actions bot commented Dec 3, 2024

PR Preview Action v1.4.8
Preview removed because the pull request was closed.
2024-12-06 15:49 UTC

@balzss
Copy link
Contributor

balzss commented Dec 3, 2024

I've checked it and seems like it was also buggy in v9, so might not be a regression in the commit you've linked. Also the spacing is a bit odd:
image

I would suggest using the gap css prop instead of adding margins to every pill/tag.

Another thing: shouldn't the input tag wrap with the pill too, instead of being on a new line:
image

Copy link
Contributor

@balzss balzss left a comment

Choose a reason for hiding this comment

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

see my comment above

<span css={styles?.layout}>
{beforeElement && (
<span css={styles?.layout}>
{beforeElement && <div css={styles?.beforePadding}></div>}
Copy link
Collaborator Author

@matyasf matyasf Dec 5, 2024

Choose a reason for hiding this comment

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

I dont like this solution, that we have an extra DOM element just to add a bit of padding. (this is needed when there is renderBeforeInput, e.g. Tags) But I could not find a better solution, what I've tried:

  1. Use a tricky CSS, that adds padding if the first child of the layout span is NOT the inputLayout: '&:has(> :first-child:not([class$="textInput__inputLayout"]))'. While this works nice in the browser it crashes in Vite tests because of a bug in a dependency: Some uses of :has throw "not a valid selector" dperini/nwsapi#123
    So using this solution means that users will need to use either the latest Jest or a patched version of Jest where nwsapi is at the latest version, which is not cool IMO.

  2. Do some JS magic to figure out the width of the renderBeforeInput elements: This is what the old code was doing, now it would need to be even more complicated because we're not wrapping renderBeforeInput in a div anymore, so we need to take care of the case that its a React fragment/text/whatever weirdness users put there.

While the current solution is a bit ugly because of the extra DOM element and the padding is added if the renderBeforeInput's width is 0, its still the best I could find.

Copy link
Contributor

Choose a reason for hiding this comment

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

As we discussed adding padding to the container would be an easier solution, please fix.

@matyasf matyasf requested review from balzss and joyenjoyer December 5, 2024 13:50
Copy link
Contributor

@joyenjoyer joyenjoyer left a comment

Choose a reason for hiding this comment

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

Please add a padding to the container instead of the divider solution.

@matyasf matyasf requested a review from joyenjoyer December 6, 2024 11:57
Copy link
Contributor

@balzss balzss left a comment

Choose a reason for hiding this comment

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

looks good. later we could simplify this by removing the margins and paddings from the Tags and using flex gap but that would require rewriting our examples and breaking existing code that users need to update

@matyasf matyasf force-pushed the fix_input_overflow branch from a3ce97e to edcab73 Compare December 6, 2024 15:30
… TextInput, Select, SimpleSelect

Closes: INSTUI-4344

When adding lots of elements to renderBeforeInput for example Tags it was overflowing the input
field. Also when there are more than one line of elements keep the input field in the same line
if there is enough space
TEST PLAN:
Add lots of elements to renderBeforeInput to Select,SimpleSelect,TextInput. They should wrap,
not overflow
@matyasf matyasf force-pushed the fix_input_overflow branch from edcab73 to 6f3723f Compare December 6, 2024 15:42
@matyasf matyasf merged commit ee9cafd into master Dec 6, 2024
10 of 11 checks passed
@matyasf matyasf deleted the fix_input_overflow branch December 6, 2024 15:48
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.

4 participants