alphagov / govuk-frontend

GOV.UK Frontend contains the code you need to start building a user interface for government platforms and services.
https://frontend.design-system.service.gov.uk/
MIT License
1.16k stars 320 forks source link

Date input component spacing problem at very narrow widths #1250

Closed andysellick closed 5 years ago

andysellick commented 5 years ago

Screen Shot 2019-03-20 at 08 49 51

If the date input is in a small enough space that it is forced to wrap, there's not enough vertical spacing between the label and the inputs above (see screenshot). Seems to occur if the component is in a container less than 200px wide.

This might seem unlikely to occur in the wild but we eventually want to use the date input component in finders to replace the existing single input field (for example on the news and communication finder). Here the component would be in a narrow side column that can be reduced to a width less than 200px before hitting the mobile break point.

(there is some right margin on the 'year' input that could be removed, possibly, although that wouldn't completely solve the issue)

NickColley commented 5 years ago

We could consider using flexbox here...

dashouse commented 5 years ago

Hey @andysellick,

This is a use case of this component that wasn't entirely expected, we tend to support something like this down to about 320px (inclusive of page gutter).

When something like this is used on a larger screen but in a small container the smaller font size won't have kicked in so the component will also be bigger than if it was 100% of a smaller screen.

There's a couple of options if you want to get this working for you now,

a) Depending on what you're doing with the other components in the refine panel you could reduce the font size to 16px which will also reduce the size of the inputs. I wouldn't imagine you'd want to do this unless all of the other form elements were also 16px

b) Create your own modifier for the input widths. Currently the widths are defines by the classes govuk-input--width-2 and govuk-input--width-4. These set a width using the ex unit.

They are a little bigger than they'd actually need to be so you could delete these classes, and make your own modifier of the govuk-date-input__input class for each input.

A small tweak would be to change the year from govuk-input--width-4 to govuk-input--width-3 and see if that helps. You'll still be able to fit 4 characters in it, the extra space is there for a autocomplete icon that wouldn't be present in your use case.

andysellick commented 5 years ago

Thanks @dashouse. @alex-ju has implemented a fix to remove the margin right from the year input and swap around the margin so each of the input/label groups has a bit of top margin, without changing the layout of anything else. Seems to work.

colinrotherham commented 5 years ago

Since date input items use display: inline-block no flexbox needed.

Adding white-space: nowrap; will prevent wrapping.

timpaul commented 5 years ago

Closing this for now, as the original issue has been addressed. We'll review Colin's proposed solution separately. Thanks everyone