Skip to content

Commit 03b7071

Browse files
Formatted Input: placeholder feature (#132)
This PR aims to add the placeholder property
1 parent 1acc0fc commit 03b7071

3 files changed

Lines changed: 24 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- property `placeholder` to `FormattedInput` component.
13+
1014
## [3.2.0] - 2025-04-30
1115

1216
### Added

cypress/cypress/component/Formatted/NumericFormat.cy.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,20 @@ it("style is correcly applied", () => {
163163

164164
cy.get(`input[id=${name}]`).should("have.attr", "style", style);
165165
});
166+
167+
it("has placeholder", () => {
168+
const name = faker.random.word();
169+
const placeholder = faker.random.words(5);
170+
171+
cy.mount(
172+
<Form
173+
onSubmit={() => {
174+
// Do nothing
175+
}}
176+
>
177+
<FormattedInput name={name} label={name} numericFormat={numericFormat} placeholder={placeholder} />
178+
</Form>,
179+
);
180+
181+
cy.get(`#${name}`).should("have.attr", "placeholder", placeholder);
182+
});

src/lib/FormattedInput.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { useFormContext } from "./context/FormContext";
1010
interface FormattedInputProps<T extends FieldValues> extends CommonInputProps<T> {
1111
patternFormat?: PatternFormatProps;
1212
numericFormat?: NumericFormatProps;
13+
placeholder?: string;
1314
}
1415

1516
const FormattedInput = <T extends FieldValues>(props: FormattedInputProps<T>) => {
@@ -33,6 +34,7 @@ const FormattedInput = <T extends FieldValues>(props: FormattedInputProps<T>) =>
3334
addonRight,
3435
className = "",
3536
hideValidationMessage = false,
37+
placeholder,
3638
} = props;
3739
const { name, id } = useSafeNameId(props.name, props.id);
3840
const { control, disabled: formDisabled } = useFormContext();
@@ -89,6 +91,7 @@ const FormattedInput = <T extends FieldValues>(props: FormattedInputProps<T>) =>
8991
}}
9092
onFocus={focusHandler}
9193
style={style}
94+
placeholder={placeholder}
9295
></NumericFormat>
9396
)}
9497

0 commit comments

Comments
 (0)