From 75249b8322d9583e23486281296d9b7e12ce181b Mon Sep 17 00:00:00 2001 From: Florian Zia Date: Fri, 13 Dec 2024 10:55:05 +0100 Subject: [PATCH 1/9] chore: Animated text input placeholder --- .../components/client/InputField.module.scss | 34 ++++++++++++++++++- src/app/components/client/InputField.tsx | 21 ++++++++---- 2 files changed, 47 insertions(+), 8 deletions(-) diff --git a/src/app/components/client/InputField.module.scss b/src/app/components/client/InputField.module.scss index 8f95ee8820d..0d4115c8f46 100644 --- a/src/app/components/client/InputField.module.scss +++ b/src/app/components/client/InputField.module.scss @@ -7,14 +7,46 @@ flex-direction: column; position: relative; + .inputFieldWrapper { + position: relative; + } + + .placeholder { + background: $color-white; + border-radius: $border-radius-sm; + color: $color-grey-40; + display: inline-block; + left: calc($spacing-sm + $spacing-xs); + line-height: 1em; + padding: 0 calc($spacing-xs * 0.5); + pointer-events: none; + position: absolute; + top: 50%; + transform-origin: top left; + transform: translateY(-50%) scale(1); + transition: transform 0.2s ease-in-out; + user-select: none; + } + + &:focus-within, + &:not(:has(:placeholder-shown)) { + .placeholder { + transform: translateY(-205%) scale(0.875); + } + } + .inputField { border: 1px solid $color-grey-30; border-radius: $border-radius-sm; color: $color-black; // Add a bit more vertical space: The next spacing step is too much. padding: calc($spacing-sm * 1.5) $spacing-md; + width: 100%; + + &::placeholder { + @include visually-hidden; + } - &::placeholder, &.noValue { color: $color-grey-40; } diff --git a/src/app/components/client/InputField.tsx b/src/app/components/client/InputField.tsx index abc2bb447df..e70415d8aee 100644 --- a/src/app/components/client/InputField.tsx +++ b/src/app/components/client/InputField.tsx @@ -38,13 +38,20 @@ export const InputField = ( } )} - + + + {inputProps.placeholder && ( + + {inputProps.placeholder} + + )} + {props.iconButton && (
{props.iconButton}
)} From 9d15c56a1d6095492fd35200532beb512927cc8f Mon Sep 17 00:00:00 2001 From: Florian Zia Date: Mon, 16 Dec 2024 10:51:36 +0100 Subject: [PATCH 2/9] chore: Make floating input field placeholder a label --- .../components/client/InputField.module.scss | 6 ++-- src/app/components/client/InputField.tsx | 35 ++++++++----------- .../client/stories/InputField.stories.ts | 19 ++++++++++ 3 files changed, 37 insertions(+), 23 deletions(-) diff --git a/src/app/components/client/InputField.module.scss b/src/app/components/client/InputField.module.scss index 0d4115c8f46..8e7664f4e1c 100644 --- a/src/app/components/client/InputField.module.scss +++ b/src/app/components/client/InputField.module.scss @@ -11,10 +11,10 @@ position: relative; } - .placeholder { + .floatingLabel { background: $color-white; border-radius: $border-radius-sm; - color: $color-grey-40; + color: $color-black; display: inline-block; left: calc($spacing-sm + $spacing-xs); line-height: 1em; @@ -30,7 +30,7 @@ &:focus-within, &:not(:has(:placeholder-shown)) { - .placeholder { + .floatingLabel { transform: translateY(-205%) scale(0.875); } } diff --git a/src/app/components/client/InputField.tsx b/src/app/components/client/InputField.tsx index e70415d8aee..e0d566ce508 100644 --- a/src/app/components/client/InputField.tsx +++ b/src/app/components/client/InputField.tsx @@ -13,6 +13,7 @@ import { useL10n } from "../../hooks/l10n"; export const InputField = ( props: AriaTextFieldProps & { iconButton?: ReactNode; + hasFloatingLabel?: boolean; }, ) => { const { isRequired, label, isInvalid, value, description } = props; @@ -29,29 +30,23 @@ export const InputField = ( return (
{label && ( -