Skip to content
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

[4.x] Change Time fieldtype from text to time input type #9662

Merged
merged 3 commits into from Mar 11, 2024

Conversation

aaronbushnell
Copy link
Contributor

This pull request changes the Time fieldtype to use <input type="time"> instead of <input type="text">. This is valuable for a couple reasons:

  1. This native fieldtype already implements incrementing and decrementing the values without needing to implement those manually
  2. 12-hour and 24-hour presentations are supported based on the user's OS locale settings (See Allow the time field to display time in 12 hour format ideas#1074)

@aaronbushnell aaronbushnell changed the title Change Time fieldtype from text to time input type [4.x] Change Time fieldtype from text to time input type Mar 4, 2024
Copy link
Member

@jasonvarga jasonvarga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice changes, thanks!

There are a couple of issues:

The new width of the time portion makes the date get cut off when used in a sidebar.

CleanShot 2024-03-04 at 14 02 05

In Firefox the time is cut off:

CleanShot 2024-03-04 at 14 03 36

I've only checked this out on Safari, Chrome, and Firefox on a Mac.

Do you know how to change to 24 hour time? Apparently it reads your system settings, but even when I tell my Mac to display 24 hours, the field doesn't change. Were you able to test that?

Swapping margin for gap and removing the hardcoded width values ensures the input field is more consistent across different browser versions and device widths
@aaronbushnell
Copy link
Contributor Author

Hey @jasonvarga, thanks a bunch! Couple updates for you:

Do you know how to change to 24 hour time? Apparently it reads your system settings, but even when I tell my Mac to display 24 hours, the field doesn't change. Were you able to test that?

Yeah, the 24-hour config varies a bit by browser. What winds up working most consistently across browsers is if your OS language defaults to a 24-hour time and you perform a restart. When I set my macOS language to "English (UK)" and restart my browser I get the 24-hour time format.

The new width of the time portion makes the date get cut off when used in a sidebar.

Good catch! I made a handful of CSS changes that should make the date, date + time, and date + time + seconds look more consistent in a sidebar and content area context:

screenshot

# Conflicts:
#	resources/js/components/fieldtypes/DateFieldtype.vue
@jasonvarga
Copy link
Member

jasonvarga commented Mar 11, 2024

When I set my macOS language to "English (UK)" and restart my browser I get the 24-hour time format.

Confirmed. Kinda stupid though. Even if I set 24 hour time in my Mac settings (pictured), it doesn't respect it. I have to use the entire alternate locale and reboot like you said. Not a fault of this PR obviously.

CleanShot 2024-03-11 at 14 45 48

Thanks!

@jasonvarga jasonvarga merged commit 66fd5e4 into statamic:4.x Mar 11, 2024
17 checks passed
@aaronbushnell
Copy link
Contributor Author

Thanks so much, @jasonvarga! Yeah, such a peculiar setting!

@aaronbushnell aaronbushnell deleted the use-time-fieldtype branch March 11, 2024 20:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants