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

Textarea with auto resize in UI #1893

Merged
merged 5 commits into from
Jun 12, 2019

Conversation

m-masataka
Copy link
Contributor

I often use comment field in Silence Form Page with multiple lines of text.
I believe auto expand field is convenient for us.

@stuartnelson3
Copy link
Contributor

hey, sorry for the long delay in responding!

I like how the text area resizes in this PR, but the questions I'm thinking about currently:

  • the text doesn't resize while I'm typing, only when focusing on the textarea. resizing while typing would probably also be nice
  • if we make the change above, is this then something that we want? GitHub, for example (since I'm using their UI right now), auto-expands this comment box as I type, and it's a nice feature that I didn't actually even notice until looking at this PR. So maybe we should add it ..

do you have the time to implement resize-on-type? I think then we could look at the code and see if it makes sense to add this.

@m-masataka
Copy link
Contributor Author

m-masataka commented May 31, 2019

@stuartnelson3 Thanks for your comment.
Now I implemented textarea resize on keypress(key type). Does this match your comment of it?

|> ceiling
|> clamp config.minRows config.maxRows
in
{ field | rows = rows }
Copy link
Member

Choose a reason for hiding this comment

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

I see that there are two ways to update rows, the first way is using the number of lines in the value and the second way is using the scrollHeight. If the first way is working, we don't really need the second way. We don't even need to extend ValidatedField to store rows, we only need to introduce a view for the comment field that calculates the rows based on the number of lines in the value.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for your review.
That’s true. Using scrollHeight is my old implementation of it.
revised it

Copy link
Member

@w0rm w0rm Jun 6, 2019

Choose a reason for hiding this comment

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

@m-masataka sorry for not making this clear. Because rows can be calculated from the value, it doesn't need to be stored in the model and can be done in the view function. The proposed change adds rows to every input, even though this is only used in the comment textarea.

What do you think of introducing a separate view function that would render the comment textarea and calculate the rows attribute?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@w0rm Sorry, I misunderstood.

Because rows can be calculated from the value, it doesn't need to be stored in the model and can be done in the view function.

Exactly.

The proposed change adds rows to every input, even though this is only used in the comment textarea.
What do you think of introducing a separate view function that would render the comment textarea and calculate the rows attribute?

I see. I think textarea must be separated.
Do you mean that create new function similar to validatedField ?
If so, I'll revise that soon.

Copy link
Member

@w0rm w0rm Jun 11, 2019

Choose a reason for hiding this comment

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

@m-masataka yeah, exactly! Just a separate function similar to validatedField for the comment textarea. The rows attribute only makes sense for textarea, we don't need it for all regular input fields.

Signed-off-by: mizukoshi-m <mizukoshi@mfeed.ad.jp>
Signed-off-by: m-masataka <m.mizukoshi.wakuwaku@gmail.com>
Signed-off-by: m-masataka <m.mizukoshi.wakuwaku@gmail.com>
Signed-off-by: m-masataka <m.mizukoshi.wakuwaku@gmail.com>
let
lineCount =
lines field.value
|> length
Copy link
Member

Choose a reason for hiding this comment

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

List is always imported in Elm, so you can write List.length here and remove import List exposing (length)

Valid ->
div [ class <| "d-flex flex-column form-group has-success " ++ classes ]
[ label [] [ strong [] [ text labelText ] ]
, htmlField
Copy link
Member

Choose a reason for hiding this comment

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

There is no need in htmlField argument, because it is always textarea.

validatedTextareaField htmlField labelText classes inputMsg blurMsg field =
let
lineCount =
lines field.value
Copy link
Member

Choose a reason for hiding this comment

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

String is always imported, so you can write String.lines here and remove import String exposing (lines) from the top

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, lack of elm knowledge.
Thank's for Review.

Copy link
Member

Choose a reason for hiding this comment

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

No worries, thanks for working on this!

Signed-off-by: m-masataka <m.mizukoshi.wakuwaku@gmail.com>
@w0rm w0rm merged commit b33a936 into prometheus:master Jun 12, 2019
DuskEagle pushed a commit to DuskEagle/alertmanager that referenced this pull request Aug 1, 2019
* textarea with auto resize

Signed-off-by: mizukoshi-m <mizukoshi@mfeed.ad.jp>

* implement resize textarea on type

Signed-off-by: m-masataka <m.mizukoshi.wakuwaku@gmail.com>

* remove scrollHeight

Signed-off-by: m-masataka <m.mizukoshi.wakuwaku@gmail.com>

* Add new function for textarea field

Signed-off-by: m-masataka <m.mizukoshi.wakuwaku@gmail.com>

* remove unnecessary code

Signed-off-by: m-masataka <m.mizukoshi.wakuwaku@gmail.com>
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.

5 participants