DEV Community

Let's Improve the textarea!

Siddharth on June 28, 2021

I improved the textarea, and I'll show you how I did it here! Here's the final result: The base We are gonna use a textarea to imp...
Collapse
 
ianwijma profile image
Ian Wijma

I've made many "improved" text fields in the past. But I always bump info many edge cases. But it's a really fun and educative process I think. Good luck!

PS: ctrl-z / undo has weird behaviour when writing some thing like <test>. You remove the content, write some more and than hit undo / ctrl-z.

Collapse
 
siddharthshyniben profile image
Siddharth

Yeah, inserting the extra characters messes up the undo tree

Collapse
 
wintercounter profile image
Victor Vincent

You can fix that by fireing keypress events instead of overwriting values.

Thread Thread
 
siddharthshyniben profile image
Siddharth

Nice tip! Will definitely try it

Collapse
 
siddharthshyniben profile image
Siddharth

That sounds intresting, could just send me the links to them if you have them on GitHub or something?

Collapse
 
siddharthshyniben profile image
Siddharth • Edited

Hey there! If you have any more ideas for more improvements, just comment down below. Here's my current Todo list:

  • Get this project on GitHub as a library or something
  • List improvements
    • Add support for -[ ] lists
  • Auto resize textareas
  • Smarter quotes – If there is a word before a quote, just insert one quote.
  • Wrap selected stuff with <insert character>
  • (no) Word wrap
  • (Highly unlikely) Find a way to not mess up the undo tree (try to use keypress events)
  • (Super highly unlikely) Multi cursor editing
Collapse
 
terabytetiger profile image
Tyler V. (he/him) • Edited
  • A11y!

How do you keyboard navigate out of the textarea when tab inserts a tab proper?

Collapse
 
siddharthshyniben profile image
Siddharth

I think I already mentioned it in the post, right?

Collapse
 
terabytetiger profile image
Tyler V. (he/him)

I'm asking because you have making the textarea more accessible as one of your motivations, but then removed tab functionality from the user - which actually causes the post to not be accessible because trying to navigate the first codepen traps the user.

Even if you move the functionality to another key, you're moving the functionality away from where the user is expecting it, and I'm not sure how you would notify the user that they now need to push something other than tab to navigate out of the box.

Thread Thread
 
siddharthshyniben profile image
Siddharth

Yeah, that's right. I've thought about it but I got no ideas, so I didn't mention it too much in the post.

Do you have any ideas on how to fix it?

Thread Thread
 
terabytetiger profile image
Tyler V. (he/him)

I think the solution is to not modify the tab functionality and include a snippet shortcut for adding tab literals?

Thread Thread
 
siddharthshyniben profile image
Siddharth

Good idea! I think what we could do is add another keybinding for inserting a tab, maybe alt + tab

Collapse
 
siddharthshyniben profile image
Siddharth

I know πŸ˜…, Maybe we could just use an alternate key? Maybe.

Collapse
 
fagnerbrack profile image
Fagner Brack • Edited

I use an international keyboard where I can press ' and then "a" to have "Γ‘". If I want to use double quotes I press " and then space. In the textarea above, it creates """" instead of "".

Nice idea but there are so many edge cases that the cost to develop something like this would be simply not worth it for the majority of the projects out there.

Collapse
 
the_one profile image
Roland Doda

Nice article. It would be great to see how you implement the "@" feature when you tag someone.

Collapse
 
siddharthshyniben profile image
Siddharth

That's a DEV specific thing, so that's a bit far on my list

Collapse
 
siddharthshyniben profile image
Siddharth

Hmm, I could add that sometime. Nice suggestion!