-
Notifications
You must be signed in to change notification settings - Fork 331
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
Dynamically position text within input prefixes and suffixes #4157
Conversation
📋 StatsFile sizes
Modules
View stats and visualisations on the review app Action run for db78328 |
display: inline-block; | ||
// Use flexbox to align text within the prefix and suffix | ||
display: flex; | ||
align-items: center; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works great 👍
Will it be an issue that the input still has line-height: 1.25
?
We've got 2x vertical alignment methods to keep in sync now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good spot. From a quick play around this doesn't seem to make a difference for me. I'll do some digging and try to understand what's going on...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah silly me. This is coming from govuk-font
. I'm personally not worried about this as I'm viewing the prefixes and suffixes as purely visual aids rather than necessarily elements of the typography. I'm also not totally sure it makes a difference for the inputs since they're already driven by padding and flexbox.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's not a worry that's fine. Wondered if you wanted the same approach on both?
@owenatgov Review wise, are we accepting there's still a very slight misalignment?
It's better than what the issue describes, but close enough to call it done? |
3172db5
to
bf5bccb
Compare
Stylesheets changes to npm packagediff --git a/packages/govuk-frontend/dist/govuk/govuk-frontend.min.css b/packages/govuk-frontend/dist/govuk/govuk-frontend.min.css
index 7036eb68b..403e85fb3 100644
--- a/packages/govuk-frontend/dist/govuk/govuk-frontend.min.css
+++ b/packages/govuk-frontend/dist/govuk/govuk-frontend.min.css
@@ -2885,7 +2885,9 @@ screen and (forced-colors:active) {
font-size: 1rem;
line-height: 1.25;
box-sizing: border-box;
- display: inline-block;
+ display: flex;
+ align-items: center;
+ justify-content: center;
min-width: 2.5rem;
height: 2.5rem;
padding: 5px;
@@ -2923,14 +2925,6 @@ screen and (forced-colors:active) {
}
}
-@media (max-width:40.0525em) {
-
- .govuk-input__prefix,
- .govuk-input__suffix {
- line-height: 1.6
- }
-}
-
@media (max-width:19.99em) {
.govuk-input__prefix,
Action run for db78328 |
Other changes to npm packagediff --git a/packages/govuk-frontend/dist/govuk/components/input/_index.scss b/packages/govuk-frontend/dist/govuk/components/input/_index.scss
index 8e276be74..b236edf84 100644
--- a/packages/govuk-frontend/dist/govuk/components/input/_index.scss
+++ b/packages/govuk-frontend/dist/govuk/components/input/_index.scss
@@ -119,26 +119,21 @@
.govuk-input__prefix,
.govuk-input__suffix {
@include govuk-font($size: 19);
-
box-sizing: border-box;
- display: inline-block;
+ // Use flexbox to align text within the prefix and suffix
+ display: flex;
+ align-items: center;
+ justify-content: center;
min-width: govuk-px-to-rem(40px);
height: govuk-px-to-rem(40px);
padding: govuk-spacing(1);
border: $govuk-border-width-form-element solid $govuk-input-border-colour;
background-color: govuk-colour("light-grey");
-
text-align: center;
- @include govuk-media-query($until: tablet) {
- line-height: 1.6;
- }
white-space: nowrap;
-
// Emphasise non-editable status of prefixes and suffixes
cursor: default;
-
flex: 0 0 auto;
-
// Split prefix/suffix onto separate lines on narrow screens
@include govuk-media-query($until: mobile) {
display: block;
Action run for db78328 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks rockin' to me 🤘
We use flex on the prefix and suffix elements themselves to vertically and horizontally centre the text inside these elements. This is opposed to using a custom line height to move text closer to the centre on small screens.
bf5bccb
to
db78328
Compare
@colinrotherham So it's on record, I think that this alignment is ok. I'm open to being disagreed with if the feelings are strong. |
@owenatgov Fine by me, was only checking against the "Why" in the issue to see if it was complete |
What/Why
Use flexbox to vertically and horizontally position the text within the input prefix and suffix elements and remove the custom line height being used to nudge the text on smaller screens.
Fixes #3900. Details in the issue.