Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions apps/website/screens/components/textarea/code/TextareaCodePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,16 @@ const sections = [
<td>Reference to the component.</td>
<td>-</td>
</tr>
<tr>
<td>ariaLabel</td>
<td>
<TableCode>string</TableCode>
</td>
<td>
Specifies a string to be used as the name for the textarea element when no <Code>label</Code> is provided.
</td>
<td>'Text area'</td>
</tr>
</tbody>
</DxcTable>
),
Expand Down
9 changes: 8 additions & 1 deletion packages/lib/src/textarea/Textarea.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,18 @@ describe("Textarea component tests", () => {
});

test("Renders with correct accessibility attributes", () => {
const { getByLabelText } = render(<DxcTextarea label="Example label" />);
const { getByLabelText } = render(<DxcTextarea label="Example label" ariaLabel="Example aria label" />);
const textarea = getByLabelText("Example label");
expect(textarea.getAttribute("aria-invalid")).toBe("false");
expect(textarea.getAttribute("aria-describedBy")).toBeNull();
expect(textarea.getAttribute("aria-required")).toBe("true");
expect(textarea.getAttribute("aria-label")).toBeNull();
});

test("Renders with correct aria-label", () => {
const { getByRole } = render(<DxcTextarea ariaLabel="Example aria label" />);
const textarea = getByRole("textbox");
expect(textarea.getAttribute("aria-label")).toBe("Example aria label");
});

test("Renders with correct initial value", () => {
Expand Down
7 changes: 3 additions & 4 deletions packages/lib/src/textarea/Textarea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const DxcTextarea = forwardRef<RefType, TextareaPropsType>(
margin,
size = "medium",
tabIndex = 0,
ariaLabel = "Text area",
},
ref
) => {
Expand All @@ -47,10 +48,7 @@ const DxcTextarea = forwardRef<RefType, TextareaPropsType>(
const isNotOptional = (value: string) => value === "" && !optional;

const isLengthIncorrect = (value: string) =>
value !== "" &&
minLength &&
maxLength &&
(value.length < minLength || value.length > maxLength);
value !== "" && minLength && maxLength && (value.length < minLength || value.length > maxLength);

const changeValue = (newValue: string) => {
if (value == null) {
Expand Down Expand Up @@ -143,6 +141,7 @@ const DxcTextarea = forwardRef<RefType, TextareaPropsType>(
aria-invalid={!!error}
aria-errormessage={error ? errorId : undefined}
aria-required={!disabled && !optional}
aria-label={label ? undefined : ariaLabel}
/>
{!disabled && typeof error === "string" && (
<ErrorMessageContainer id={errorId} role="alert" aria-live={error ? "assertive" : "off"}>
Expand Down
4 changes: 4 additions & 0 deletions packages/lib/src/textarea/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ type Props = {
* Value of the tabindex attribute.
*/
tabIndex?: number;
/**
* Specifies a string to be used as the name for the textarea element when no `label` is provided.
*/
ariaLabel?: string;
};
/**
* Reference to the component.
Expand Down
Loading