Skip to content

Conversation

heozeop
Copy link
Contributor

@heozeop heozeop commented Jul 23, 2021

Editable textarea element to handle multi-line input within editable context.

Closes #1622

📝 Description

Add EditableTextare element to handle multiline input with editable context

🚀 New behavior

new line input is possible with editable context.

📝 Additional Information

Use union type for inputRef

// editable/src/use-editable.ts
...
const [value, setValue] = useControllableState({
  defaultValue: defaultValue || "",
  value: valueProp,
  onChange: onChangeProp,
})
...
const inputRef = useRef<HTMLInputElement | HTMLTextAreaElement>(null)

Because the editable context has one controllable state as default,
use union type for input to maintain compatibility with the above condition.

split test suite for editable textarea

Despite of the similarity of editable.test.tsx and editableTextarea.test.tsx, which is the test file in editable pakage,
I choose to split test suite to minimize lines of suite.

@changeset-bot
Copy link

changeset-bot bot commented Jul 23, 2021

🦋 Changeset detected

Latest commit: 230a9c3

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 7 packages
Name Type
@chakra-ui/anatomy Minor
@chakra-ui/editable Minor
@chakra-ui/theme Minor
@chakra-ui/react Patch
@chakra-ui/toast Patch
@chakra-ui/props-docs Patch
@chakra-ui/test-utils Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Jul 23, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/chakra-ui/chakra-ui-storybook/HdExSTCaswsUev2gWd2wCyoat2XJ
✅ Preview: https://chakra-ui-storybook-git-fork-heozeop-feat-edit-41088e-chakra-ui.vercel.app

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jul 23, 2021

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 230a9c3:

Sandbox Source
create-react-app-ts Configuration

@smkhalsa
Copy link

smkhalsa commented Aug 2, 2021

This is a feature that we'd like to use. Is there anything holding this up?

Copy link
Contributor

@takethefake takethefake left a comment

Choose a reason for hiding this comment

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

Hej @heozeop thanks for your Contribution.

Your code looks good to me in general, but it feels like we're mixing things up in this by making use-editable work with HTMLInputElement and HTMLTextAreaElement i would rather make use-editable generic and as well split up editable into two components editable-input and editable-textarea which use the generic version of use-editable with their respective Element-Type.

Splitting this component into two would also clarify the props in the documentation since the Textarea-props aren't displayed their although they could be used like this.

This is just my opinion, before doing any refactoring I would wait for one of the core members of the chakra team to give some input. @segunadebayo @with-heart @TimKolberger

@cpvalente
Copy link

I was wondering if there is a timeline for reviewing the PR with the new changes? It would be fantastic to be able to use this

@mSigson
Copy link

mSigson commented Jan 12, 2022

Hoping this feature will be merged and deployed soon - I would have immediate use for this on a current project for a client.

Thank you @heozeop and @takethefake for your time and efforts put towards implementing this change!

@heozeop
Copy link
Contributor Author

heozeop commented Feb 3, 2022

@takethefake @with-heart @TimKolberger
Hi! guys!

I just resolved the error which is occurred during build/lint/test.

It would be great if you leave some comments or merge the feature!

Thanks!

Context

FYI

  • PropGetterV2 : util type defined on @chakra-ui/react-utils, which omit height, color and width from merged props.

Issue: attribute 'height' incompatible

While build/lint/test, github action throw the error below (error page).

  • Type of height attribute of html element is incompatible with chakra's height

Try: update type of editable input/textarea props

I thought that returns of 'editable hook' should focus on functionality of editable(well, there is htmlProps which is the result of rest operation, but, anyway.).

So, I updated 'editable input and textarea props type' to PropGetterV2 from PropGetter to resolve incompatibility of style property, especially height

I want your opinion about using PropGetterV2

Should we support height of html attributes on editable input/textarea props explicitly?

What do you think?

@heozeop
Copy link
Contributor Author

heozeop commented Feb 4, 2022

situation

  • I started working on this PR about a year ago.
  • With cli update, conflict occurred. So I merge main branch to resolve that.
  • Due to error on main branch (like storybook button error), yarn lint always failed.
  • So I decided to revert merge commit and force push.
  • Conflict is the result of dumb decision.

Please share your opinion

I think I have two options.

  1. fix all errors on main branch.
    • storybook: button, simple-grid
    • test: system
  2. create new pr with same content from new branch that start from current main branch.

@takethefake @TimKolberger @with-heart
What do you think about above options? Are there better options to solve this problem?

Thanks!

@TimKolberger
Copy link
Contributor

The lint errors on main are fixed for now 🎉
I feel you - long running feature branches are a pain to work with.

My personal preference is to rebase feature branches onto main to prevent big merge commits.
This can be a pain as well if there are many merge conflicts and commits.

This PR adds a great feature which I'd love to merge when it's ready.

@heozeop
Copy link
Contributor Author

heozeop commented Feb 5, 2022

Thank you very much @TimKolberger!

Thanks for your comment and commit, I'm really relieved.

As you recommended, I rebased this branch onto chakra-ui:main.

Thank you again!

@awartoft
Copy link

Any chance we might see this merged soon?

@heozeop
Copy link
Contributor Author

heozeop commented Feb 17, 2022

Hello! @TimKolberger @with-heart! Can you merge this PR or review the change?

Copy link
Contributor

@TimKolberger TimKolberger left a comment

Choose a reason for hiding this comment

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

The code looks good! I added a comment regarding the theme styles, my apologies to not catching this earlier.

@heozeop
Copy link
Contributor Author

heozeop commented Feb 28, 2022

Hello! @TimKolberger
I thought that there are some wrong codes on main branch! (fail test on switch, use-breakpoint-value)
Should I have to wait until fix commit about them?
Sorry for bothering.

@TimKolberger
Copy link
Contributor

No worries 😊
Have you tried building the repository before running the tests? The main branch just ran successfully on my machine with yarn && yarn build && yarn test

heozeop and others added 9 commits February 28, 2022 22:49
To maintain consistency of editable context,

use union type of textarea and input element to reference

element.
To simplify usage and  the type safety, add types where it declared.
The 'height' attribute type that html elemenet delivered is
not compatable with 'height' of chakra. So, use PropGetterV2 to
resolve style incompatiblity.
@TimKolberger
Copy link
Contributor

Hey @heozeop!

I really appreciate the work you put into this 💖

Needless to say that this PR was open for far too long 😪

Kindly allow me to bring this over the finish line:

  1. Added the textarea element to the anatomy package to allow theme styles to be added
  2. Reused the input styles in the theme for the textarea component, which seems like a good starting point for further customization
  3. Updated the changelog to address the target the users of Chakra UI, not the maintainers/contributors
  4. and rebased onto the main branch

@all-contributors add @heozeop for code

@allcontributors
Copy link
Contributor

@TimKolberger

I've put up a pull request to add @heozeop! 🎉

@TimKolberger TimKolberger merged commit fbe9462 into chakra-ui:main Feb 28, 2022
@github-actions github-actions bot mentioned this pull request Feb 28, 2022
@kk21
Copy link
Contributor

kk21 commented Mar 2, 2022

I am not sure if something changed for using controlled value (React useState) of Editable for normal Input field.

<Editable value={name} onChange={(value) => setName(value)}>

Now setting a new value in useEffect doesnt seem to propagate into the "inner" value of Editable.
Pressing "Esc" key in edit mode after making some temporary edit will also change the value when it shld not.

@TimKolberger
Copy link
Contributor

Hi @kk21,

Kindly open an issue with a reproduction in CodeSandbox. It is hard to verify an issue without actual code.

I don't see any changes regarding the value handling in this PR, it is still using the useControllableState hook - a reproduction would help a lot.

@kk21
Copy link
Contributor

kk21 commented Mar 2, 2022

Opened an issue here
#5670

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.

Request to add EditableTextArea to [Editable] component
8 participants