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(react): enable textarea to limit text input to set amount of words #12906

Merged

Conversation

matejoslav
Copy link
Contributor

@matejoslav matejoslav commented Dec 31, 2022

Co-authored-by: SamChinellato [email protected]
Co-authored-by: stevenpatrick009 [email protected]

Closes #13788

Added functionality to textArea component to limit the number of words the user can type. Also updated the useAnouncer to handle new wording by allowing it to either display "x characters left" or "x words left" based on args passed in.

Changelog

New

  • textArea component has now word counter mode and can now limit the amount of words user types
  • added more tests for the textArea component

Changed

  • useAnouncer can now take the entityName and use that to display the "x left"
  • added tests for useAnnouncer

Testing / Reviewing

  • run the storybook for react components
  • navigate to the textArea component
  • select the "WithWordCounter" textArea type
  • type in few words and observe the counter increase
  • try to type in more words than the limit and observe that user can not add more words
  • try to paste in text with more words than the limit and observe that the text has been cut to match the word limit

@github-actions
Copy link
Contributor

github-actions bot commented Dec 31, 2022

DCO Assistant Lite bot All contributors have signed the DCO.

@matejoslav
Copy link
Contributor Author

I have read the DCO document and I hereby sign the DCO.

@matejoslav
Copy link
Contributor Author

recheck

@netlify
Copy link

netlify bot commented Dec 31, 2022

Deploy Preview for v11-carbon-react ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 42a0616
🔍 Latest deploy log https://app.netlify.com/sites/v11-carbon-react/deploys/656b6274f66c480008a56501
😎 Deploy Preview https://deploy-preview-12906--v11-carbon-react.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@netlify
Copy link

netlify bot commented Dec 31, 2022

Deploy Preview for carbon-elements ready!

Name Link
🔨 Latest commit 71ee273
🔍 Latest deploy log https://app.netlify.com/sites/carbon-elements/deploys/6531acbcd755c3000840dd52
😎 Deploy Preview https://deploy-preview-12906--carbon-elements.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@sstrubberg
Copy link
Member

@matejoslav thank you so much for the PR. Two things as you're building this out.

  1. Have you considered any error message handling for when a user reaches their limit?
  2. Updates to the documentation on the website reflecting this enhancement.

tw15egan and others added 2 commits January 9, 2023 08:54
Fix tests affected by the merge to properly use the selected testing library.
Change TextArea component to remove duplicated use of the useRef hook.
@matejoslav
Copy link
Contributor Author

@sstrubberg Good points.

For point number 2, will make relevant doc updates and push them.

For point number 1, wanted to make the component behave in similar way to having a maximum character limit, at the moment the user cannot exceed the amount of words if they have reached the limit, the announcer message is also displayed showing 0 words left. Not sure if a more visual error handling is needed but happy to add one if you think it would benefit the user experience.

@matejoslav
Copy link
Contributor Author

Just checked the website repo, is it okay to assume that this change would have to be merged first and then we would add the feature description there or would you want them to be done at the same time?

@sstrubberg
Copy link
Member

Just checked the website repo, is it okay to assume that this change would have to be merged first and then we would add the feature description there or would you want them to be done at the same time?

correct, merge first, then document. Just didn't want that part to get lost :)

@tay1orjones
Copy link
Member

@matejoslav Looks like all-contributors needs to be ran again to resolve the conflict with main

@aledavila
Copy link
Contributor

Bump @matejoslav

@matejoslav
Copy link
Contributor Author

Hello, I am looking into it now 👍

@matejoslav
Copy link
Contributor Author

For some reason I am getting test failure for "Simple date picker › should initialize a calendar when using react.lazy"
I did a clean clone of the carbon repository and getting the same issue.

@matejoslav
Copy link
Contributor Author

@francinelucca check please if it now works as expected

@matejoslav
Copy link
Contributor Author

The contributorsrc and Readme seem to have been altered and the order of the people was changed, could you please check and advise what to do?

Copy link
Collaborator

@francinelucca francinelucca left a comment

Choose a reason for hiding this comment

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

Storybook issue seems to be fixed now, LGTM!

@francinelucca
Copy link
Collaborator

francinelucca commented Nov 28, 2023

The contributorsrc and Readme seem to have been altered and the order of the people was changed, could you please check and advise what to do?

Might be worth to copy/paste the file from main, add your changes and commit to solve conflicts, your call though!

Copy link
Member

@alisonjoseph alisonjoseph left a comment

Choose a reason for hiding this comment

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

LGTM!

@github-actions github-actions bot added this pull request to the merge queue Dec 4, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks Dec 4, 2023
@tay1orjones tay1orjones merged commit 01b1009 into carbon-design-system:main Dec 4, 2023
22 checks passed
danoro96 pushed a commit to danoro96/carbon that referenced this pull request Jan 18, 2024
…ds (carbon-design-system#12906)

* feat(react): enable textarea to limit text input to set amount of words

Co-authored-by: SamChinellato <[email protected]>
Co-authored-by: stevenpatrick009 <[email protected]>

* test(textArea): fix tests and component

Fix tests affected by the merge to properly use the selected testing library.
Change TextArea component to remove duplicated use of the useRef hook.

* docs(developer handbook): change max characters for line in commit body

* fix(docs): regenerated contributors to resolve merge conflict

* revert sync file changes

* fix(TextArea): fixed eslint complaints

* refactor(TextArea): changes to counterMode and storybook

changed wording for counterMode to be character or word
removed storybook entry

* refactor(TextArea): removed unused test

* docs(README): added contributors

* revert(package.json & developer-handbook.md): reverted 90 limit to 80

* chore(format): run yarn format

* fix(README): fixed the contributors formatting

* refactor(TextArea): function to get initial text count

* refactor(useAnnouncer): made entityName have default value

* refactor(TextArea): use function to calculate text count in useEffect

* fix(TextArea): ignore max count limit when counter is disabled

* fix: fixed contributors list

* chore(TextArea): trim words on paste and add missing tests

* chore(TextArea): remove console log

* chore: Update packages/react/src/components/TextArea/__tests__/TextArea-test.js

Co-authored-by: Francine Lucca <[email protected]>

* chore: remove redundant event definition in test

* fix(TextArea): fix count not updating when switching mode

* fix(TextArea): fix onPaste function

* fix(TextArea): fix lint errors and tests logic

* fix(contributors): revert list to what is on main

* fix: add contributors

---------

Co-authored-by: SamChinellato <[email protected]>
Co-authored-by: stevenpatrick009 <[email protected]>
Co-authored-by: TJ Egan <[email protected]>
Co-authored-by: Andrea N. Cardona <[email protected]>
Co-authored-by: Francine Lucca <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

TextArea word limit: implementation
9 participants