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

feat: support multiline for EditableText #2683

Merged

Conversation

gabriel-amram
Copy link
Contributor

This PR introduces the ability to support multiline in EditableText
if multiline is passed it will render a "textarea" instead of an input that cannot be resized by the user, and instead will grow/shrink according to its content up to a certain max-width or max-height defined by the container.

When using Shift+Enter a new line will be added. Hitting Enter will defocus and change the value

This is useful for users who might want to have a long description and would like to be able to edit it and change the content with line breaks.

When multiline is used, ellipsis is removed from the "view" block and from the "textarea".

@gabriel-amram gabriel-amram requested a review from a team as a code owner December 26, 2024 14:57
Copy link
Member

@talkor talkor left a comment

Choose a reason for hiding this comment

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

Thank you for the contribution! Great addition
Please see my comments :)

@gabriel-amram gabriel-amram requested a review from talkor December 31, 2024 07:49
Comment on lines +186 to +189
setInputHeight(
Math.max(
textarea.scrollHeight + textareaBorderBoxSizing.current,
textareaLineHeight.current + textareaBorderBoxSizing.current
Copy link
Member

Choose a reason for hiding this comment

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

Just one thought, looks like the only difference in the dimensions is 2px, and there's no difference in paddings/line heights etc between the different variants, so looks like doing just:
setInputHeight(textarea.scrollHeight + 2); works exactly the same and it can save the getComputeStyle and the other calculations in calculateTextareaHeightAttrs (which already have some default static numbers). Giving it auto in the beginning will already make it take the the currect box size. WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

actually the question gets back to you :)
technically its only 2px because the border-top/bottom-width is 1px (or 2px overall)
border-box should have included the border as well as the padding, but it doesn't

do we want to just rely on always having this border/padding setting and that the user cannot add anything on their own using overwriting css?
@talkor

Copy link
Member

@talkor talkor Dec 31, 2024

Choose a reason for hiding this comment

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

Well it is border-box, it's just that scrollHeight is based purely on the content and padding of the element's scrollable content, without the borders.
We don't want users to override CSS as it can make design inconsistent so I wouldn't take it into consideration, generally speaking we support the variants we officially provide so it's ok :)
@gabriel-amram

@talkor
Copy link
Member

talkor commented Dec 31, 2024

Looks great @gabriel-amram ! Only one thought which I commented, and I did some quick QA and found two things worth checking:

  • When focused on the textarea and clicking outside in the same block it will not blur
  • When going into edit mode the cursor will be in the beginning of the text instead of the last character which I think makes the experience better

@talkor
Copy link
Member

talkor commented Dec 31, 2024

  • When focused on the textarea and clicking outside in the same block it will not blur
Screenshot 2024-12-31 at 11 49 50

I mean when clicking on the purple area. I think it's because the 400px width, probably changing it to max-width instead will fix it

@gabriel-amram
Copy link
Contributor Author

Looks great @gabriel-amram ! Only one thought which I commented, and I did some quick QA and found two things worth checking:

  • When focused on the textarea and clicking outside in the same block it will not blur
  • When going into edit mode the cursor will be in the beginning of the text instead of the last character which I think makes the experience better

@talkor
the first one, is just a story thing, i removed the wrapping div so its clearer and it works
the second one, this is the default behaviour of browsers (input on focus goes to end of text, textarea to start). i added a piece of code on focus that makes sure that we always go to end of text for both
(this might feel broken though if people are more used to one rather than the other)

Copy link
Member

@talkor talkor left a comment

Choose a reason for hiding this comment

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

Thank you!
IMO worth simplifying the height calculation nevertheless

@talkor talkor merged commit 8c4bf29 into mondaycom:master Dec 31, 2024
7 of 8 checks passed
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.

2 participants