Skip to content

Commit

Permalink
Added unFocusTextArea to manage text area blur functionality (#286)
Browse files Browse the repository at this point in the history
  • Loading branch information
baiamansama authored Dec 17, 2024
1 parent 4f53e85 commit 45fa219
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
15 changes: 15 additions & 0 deletions __tests__/hooks/internal/useTextAreaInternal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,21 @@ describe("useTextAreaInternal Hook", () => {
expect(result.current.textAreaDisabled).toBe(false);
});

it("should blur on text area when blurTextArea is called", () => {
const callRcbEventMock = jest.fn();
mockUseRcbEventInternal.mockReturnValue({
callRcbEvent: callRcbEventMock,
});

const { result } = renderHook(() => useTextAreaInternal());

act(() => {
result.current.blurTextArea();
});

expect(mockInputRef.current.blur).toHaveBeenCalled();
});

// let initialTextAreaDisabled = false;

/* it("should toggle textAreaDisabled state", () => {
Expand Down
14 changes: 12 additions & 2 deletions src/hooks/internal/useTextAreaInternal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,16 @@ export const useTextAreaInternal = () => {
}, [textAreaDisabled]);

/**
* Retrieves text area value.
* Blurs on text area.
*/
const blurTextArea = useCallback(() => {
if (inputRef.current) {
inputRef.current.blur();
}
}, []);
/**
* Retrieves text area value.
*/
const getTextAreaValue = useCallback(() => {
if (inputRef && inputRef.current) {
Expand Down Expand Up @@ -140,7 +149,8 @@ export const useTextAreaInternal = () => {
setTextAreaValue,
updateTextAreaFocus,
focusTextArea,
blurTextArea,
toggleTextAreaDisabled,
toggleTextAreaSensitiveMode
};
};
};
8 changes: 5 additions & 3 deletions src/hooks/useTextArea.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export const useTextArea = () => {
toggleTextAreaSensitiveMode,
getTextAreaValue,
setTextAreaValue,
focusTextArea
focusTextArea,
blurTextArea
} = useTextAreaInternal();

return {
Expand All @@ -27,6 +28,7 @@ export const useTextArea = () => {
toggleTextAreaSensitiveMode,
getTextAreaValue,
setTextAreaValue,
focusTextArea
focusTextArea,
blurTextArea
};
};
};

0 comments on commit 45fa219

Please sign in to comment.