From 9868ab5364b6776b3782c8a0fb5cfa8b7581e9f0 Mon Sep 17 00:00:00 2001 From: Titani Labaj <39532947+tlabaj@users.noreply.github.com> Date: Tue, 14 Jan 2025 12:17:36 -0500 Subject: [PATCH] feat(Text area): Add resize disable feature (#11383) * feat(Text area): Add reasize disable feature * change disabled to none * update tests * add resize none example --- .../src/components/TextArea/TextArea.tsx | 15 ++++++++------- .../TextArea/__tests__/TextArea.test.tsx | 18 ++++++++++++++++++ .../components/TextArea/examples/TextArea.md | 6 ++++++ .../examples/TextAreaResizableNone.tsx | 14 ++++++++++++++ 4 files changed, 46 insertions(+), 7 deletions(-) create mode 100644 packages/react-core/src/components/TextArea/examples/TextAreaResizableNone.tsx diff --git a/packages/react-core/src/components/TextArea/TextArea.tsx b/packages/react-core/src/components/TextArea/TextArea.tsx index 30db54edbc7..2879ef2cb91 100644 --- a/packages/react-core/src/components/TextArea/TextArea.tsx +++ b/packages/react-core/src/components/TextArea/TextArea.tsx @@ -8,7 +8,8 @@ import { FormControlIcon } from '../FormControl/FormControlIcon'; export enum TextAreResizeOrientation { horizontal = 'horizontal', vertical = 'vertical', - both = 'both' + both = 'both', + none = 'none' } export enum TextAreaReadOnlyVariant { @@ -37,7 +38,7 @@ export interface TextAreaProps extends Omit, 'onC /** A callback for when the text area value changes. */ onChange?: (event: React.ChangeEvent, value: string) => void; /** Sets the orientation to limit the resize to */ - resizeOrientation?: 'horizontal' | 'vertical' | 'both'; + resizeOrientation?: 'horizontal' | 'vertical' | 'both' | 'none'; /** Custom flag to show that the text area requires an associated id or aria-label. */ 'aria-label'?: string; /** @hide A reference object to attach to the text area. */ @@ -118,10 +119,10 @@ class TextAreaBase extends React.Component { onFocus, ...props } = this.props; - const orientation = `resize${capitalize(resizeOrientation)}` as - | 'resizeVertical' - | 'resizeHorizontal' - | 'resizeBoth'; + const orientation = + resizeOrientation !== 'none' + ? (`resize${capitalize(resizeOrientation)}` as 'resizeVertical' | 'resizeHorizontal' | 'resizeBoth') + : undefined; const hasStatusIcon = ['success', 'error', 'warning'].includes(validated); return ( @@ -130,7 +131,7 @@ class TextAreaBase extends React.Component { styles.formControl, readOnlyVariant && styles.modifiers.readonly, readOnlyVariant === 'plain' && styles.modifiers.plain, - resizeOrientation && styles.modifiers[orientation], + resizeOrientation !== 'none' && styles.modifiers[orientation], isDisabled && styles.modifiers.disabled, hasStatusIcon && styles.modifiers[validated as 'success' | 'warning' | 'error'], className diff --git a/packages/react-core/src/components/TextArea/__tests__/TextArea.test.tsx b/packages/react-core/src/components/TextArea/__tests__/TextArea.test.tsx index 2cfc37f2aa0..959e12f33c7 100644 --- a/packages/react-core/src/components/TextArea/__tests__/TextArea.test.tsx +++ b/packages/react-core/src/components/TextArea/__tests__/TextArea.test.tsx @@ -1,4 +1,5 @@ import React from 'react'; +import '@testing-library/jest-dom'; import { render, screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; @@ -93,6 +94,16 @@ test('Text area is not invalid by default', () => { expect(screen.getByRole('textbox')).not.toBeInvalid(); }); +test('Renders vertically & resizable text area by default', () => { + render(