Skip to content

Commit

Permalink
chore: Add correct spacing for floating input labels
Browse files Browse the repository at this point in the history
  • Loading branch information
flozia committed Dec 20, 2024
1 parent 99778fe commit 24181f6
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions src/app/components/client/InputField.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
border-radius: $border-radius-sm;
color: $color-black;
display: inline-block;
left: $spacing-md;
// Add a bit more space: The next spacing step is too much.
left: calc($spacing-sm * 1.5);
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);
transform: translate(-0.05em, -50%) scale(1);
transition: transform 0.2s ease-in-out;
user-select: none;
}
Expand All @@ -32,8 +33,8 @@
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;
// Add a bit more space: The next spacing step is too much.
padding: calc($spacing-sm * 1.5);
width: 100%;

&.noValue {
Expand Down Expand Up @@ -61,25 +62,21 @@
}

&:has(.floatingLabel) {
&::placeholder {
::placeholder {
@include visually-hidden;
}

.inputField {
padding: $spacing-md;
// Move the value string off-center.
padding: calc($spacing-md * 1.25) calc($spacing-sm * 1.5) $spacing-xs;
}
}

&:focus-within,
&:not(:has(:placeholder-shown)) {
&:has(.floatingLabel) {
.inputField {
padding: calc($spacing-md + $spacing-sm) $spacing-md $spacing-sm;
}
}

.floatingLabel {
transform: translateY(-125%) scale(0.75);
color: $color-grey-40;
// Make the floating label visually align with the input value.
transform: translate(-0.05em, -115%) scale(0.75);
}
}

Expand Down

0 comments on commit 24181f6

Please sign in to comment.