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

Added unFocusTextArea to manage text area blur functionality #286

Merged
merged 2 commits into from
Dec 17, 2024

Conversation

baiamansama
Copy link
Contributor

@baiamansama baiamansama commented Dec 16, 2024

Description

This PR introduces the unFocusTextArea functionality in the useTextAreaInternal hook, which allows programmatic removal of focus from the text area. This complements the existing focusTextArea method and provides additional control over the text area's behavior.
Closes #(issue)

What change does this PR introduce?

Please select the relevant option(s).
NA

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update (changes to docs/code comments)

What is the proposed approach?

The unFocusTextArea method was added as a useCallback function within the useTextAreaInternal hook. It leverages the blur method on the inputRef to remove focus from the text area. Additionally, a new test case was created to verify this behavior, ensuring it works as intended without impacting existing functionality.

Checklist:

  • The commit message follows our adopted guidelines
  • Testing has been done for the change(s) added (for bug fixes/features)
  • Relevant comments/docs have been added/updated (for bug fixes/features)

@baiamansama baiamansama force-pushed the feature/unfocus-text-area branch from b5a3bcc to 3e7d639 Compare December 17, 2024 01:23
Copy link
Owner

@tjtanjin tjtanjin left a comment

Choose a reason for hiding this comment

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

Thank you for the PR 😊 Some nits to fix!

Comment on lines +162 to +165
const callRcbEventMock = jest.fn();
mockUseRcbEventInternal.mockReturnValue({
callRcbEvent: callRcbEventMock,
});
Copy link
Owner

Choose a reason for hiding this comment

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

This is actually unused, the text area currently only emits an event for text change. That said, it might be a good idea to emit events for focusing/blurring the text area in future (topic for another time).

@@ -105,7 +105,16 @@ export const useTextAreaInternal = () => {
}, [textAreaDisabled]);

/**
* Retrieves text area value.
* Focuses on text area.
Copy link
Owner

Choose a reason for hiding this comment

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

This comment needs to be updated as well.

* Retrieves text area value.
* Focuses on text area.
*/
const unFocusTextArea = useCallback(() => {
Copy link
Owner

Choose a reason for hiding this comment

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

Instead of unFocusTextArea, let's go with blurTextArea which will be better inline with the DOM APIs (do rename the relevent parts accordingly).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

applied changes

Copy link
Owner

@tjtanjin tjtanjin left a comment

Choose a reason for hiding this comment

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

Thanks for the changes!

@tjtanjin tjtanjin merged commit 45fa219 into tjtanjin:main Dec 17, 2024
7 of 8 checks passed
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.

2 participants