Skip to content

Commit 78ba792

Browse files
committed
Update Password block to enable having something else than 'your password must contain as hint'
1 parent 67462ba commit 78ba792

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

.storybook/DocsContainer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export const DocsContainer = ({ children, context }) => {
3131
<>
3232
<style>{`
3333
body {
34-
padding: 0 !important,
34+
padding: 0 !important;
3535
background-color: ${backgroundColor};
3636
}
3737

src/blocks/PasswordInput.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ export type PasswordInputProps = Omit<
1919
"state" | "stateRelatedMessage" | "iconId" | "classes"
2020
> & {
2121
classes?: Partial<Record<"root" | "input" | "label" | "checkbox", string>>;
22+
/** Default "Your password must contain:", if empty string the hint wont be displayed */
23+
messagesHint?: ReactNode;
2224
messages?: {
2325
severity: PasswordInputProps.Severity;
2426
message: ReactNode;
@@ -41,6 +43,8 @@ export namespace PasswordInputProps {
4143
* */
4244
export const PasswordInput = memo(
4345
forwardRef<HTMLDivElement, PasswordInputProps>((props, ref) => {
46+
const { t } = useTranslation();
47+
4448
const {
4549
className,
4650
label,
@@ -51,13 +55,12 @@ export const PasswordInput = memo(
5155
style,
5256
messages = [],
5357
nativeInputProps,
58+
messagesHint = t("your password must contain"),
5459
...rest
5560
} = props;
5661

5762
assert<Equals<keyof typeof rest, never>>();
5863

59-
const { t } = useTranslation();
60-
6164
const inputId = (function useClosure() {
6265
const id = useId();
6366

@@ -113,9 +116,11 @@ export const PasswordInput = memo(
113116
id={messagesGroupId}
114117
aria-live="assertive"
115118
>
116-
<p className={fr.cx("fr-message")} id={messageGroupId}>
117-
{t("your password must contain")}
118-
</p>
119+
{messagesHint !== "" && (
120+
<p className={fr.cx("fr-message")} id={messageGroupId}>
121+
{messagesHint}
122+
</p>
123+
)}
119124
{messages.map(({ severity, message }, index) => (
120125
<p
121126
key={index}

stories/blocks/PasswordInput.stories.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,15 @@ const { meta, getStory } = getStoryFactory({
1313
"disabled": {
1414
"control": { "type": "boolean" }
1515
},
16-
1716
"nativeInputProps": {
1817
"description": `An object that is forwarded as props to te underlying native \`<input />\` element.
1918
This is where you pass the \`name\` prop or \`onChange\` for example.`,
2019
"control": { "type": null }
20+
},
21+
"messagesHint": {
22+
"description": `The text that is displayed before the list of messages.
23+
Default to "Your password must contain:" (internationalized).
24+
If you pass an empty string, the hint block wont be displayed.`
2125
}
2226
},
2327
"doHideImportInstruction": true

0 commit comments

Comments
 (0)