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] Set cursor position with mouse click #4

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

LauraAubin
Copy link
Owner

@LauraAubin LauraAubin commented Nov 3, 2022

Closes #2

What does this accomplish?

This PR implements a regular <textarea /> with the ability to click anywhere within the space to place the cursor. This allows you to bypass new lines and unchartered area so that you can start typing without the need to mash your space bar.

How is this done?

Setting the cursor in the y-axis requires us to use a consistent line-height CSS property and perform a quick calculation using the clicked y-coordinate to determine which line we are on:

  const selectedRow = mouseCoordinates?.y ? Number((mouseCoordinates?.y / 15).toFixed()) : 1;

We then add more new lines to the text area's state using \n if the clicked space is outside the bounds of our existing content. The cursor will automatically be placed on the last line.

In order to set the cursor in the x-axis,

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.

[TextArea] - Set cursor position with mouse click
1 participant