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(ui-form): adding support for labelHidden prop #457

Merged
merged 2 commits into from
Apr 1, 2024
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
1 change: 1 addition & 0 deletions packages/documentation/src/Form/TextInput.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default {
inputClassName: "",
className: "",
mode: "system",
labelHidden: false,
},
argTypes: {
mode: {
Expand Down
1 change: 1 addition & 0 deletions packages/documentation/src/Form/TextInputMask.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export default {
error: false,
inputClassName: "",
className: "",
labelHidden: false,
},
argTypes: {
focusMode: {
Expand Down
3 changes: 2 additions & 1 deletion packages/ui-form/src/components/TextInput/TextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const TextInput = React.forwardRef<HTMLInputElement, TextInputProps>(
noBorder = false,

labelId,
labelHidden = false,
type = "text",

helperText = "",
Expand Down Expand Up @@ -79,7 +80,7 @@ export const TextInput = React.forwardRef<HTMLInputElement, TextInputProps>(
!raw && { style: { paddingRight: inputPaddingRight } })}
{...extraProps}
/>
{!raw && (
{!raw && !labelHidden && (
<label
aria-hidden={true}
htmlFor={inputId}
Expand Down
14 changes: 2 additions & 12 deletions packages/ui-form/src/components/TextInput/TextInputMask.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { useMergeRefs } from "@versini/ui-hooks";
// import { IconHide, IconShow } from "@versini/ui-icons";
import { LiveRegion } from "@versini/ui-private";
import React, { useEffect, useRef, useState } from "react";

// import { ButtonIcon } from "..";
import { TextInput } from "./TextInput";
import type { TextInputMaskProps } from "./TextInputTypes";

Expand All @@ -26,6 +24,7 @@ export const TextInputMask = React.forwardRef<
name,
disabled,
label,
labelHidden,
onMaskChange,

onChange,
Expand Down Expand Up @@ -164,6 +163,7 @@ export const TextInputMask = React.forwardRef<
ref={mergedInputRef}
name={name}
label={label}
labelHidden={labelHidden}
type={masked ? "password" : "text"}
disabled={disabled}
spacing={spacing}
Expand All @@ -178,16 +178,6 @@ export const TextInputMask = React.forwardRef<

disabled: disabled,
})}
// rightElement={
// <ButtonIcon
// label={buttonLabel}
// onClick={handleShowMaskButtonClick}
// onBlur={handleTextInputMaskBlur}
// disabled={disabled}
// >
// {masked ? <IconShow /> : <IconHide />}
// </ButtonIcon>
// }
{...otherProps}
/>

Expand Down
4 changes: 4 additions & 0 deletions packages/ui-form/src/components/TextInput/TextInputTypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ export type CommonTextInputProps = {
* CSS class(es) to add to the actual textarea element.
*/
inputClassName?: string;
/**
* Hides the label visually but retain accessible relationship with the TextInput.
*/
labelHidden?: boolean;
/**
* Id to use for the TextInput label.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,20 @@ describe("TextInput modifiers", () => {
expect(input.className).toContain("border-transparent");
});

it("should render a text input with a hidden label", async () => {
render(
<TextInput
label="hello world"
name="toto"
labelHidden
data-testid="txtnpt-1"
/>,
);
const label = await screen.findAllByText("hello world");
screen.debug(label);
expect(label.length).toBe(1);
});

it("should render a raw text input with no styling", async () => {
render(<TextInput label="toto" name="toto" raw data-testid="txtnpt-1" />);
const input = await screen.findByTestId("txtnpt-1");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,25 @@ describe("TextInputMask modifiers", () => {
expect(input.className).toContain("border-transparent");
});

it("should render a text input with a hidden label", async () => {
render(
<TextInputMask
label="hello world"
name="toto"
labelHidden
data-testid="txtnpt-1"
rightElement={
<ButtonIcon>
<IconHide />
</ButtonIcon>
}
/>,
);
const label = await screen.findAllByText("hello world");
screen.debug(label);
expect(label.length).toBe(1);
});

it("should render a raw text input with no styling", async () => {
render(
<TextInputMask
Expand Down
Loading