Skip to content

Commit 5da6968

Browse files
authored
Normalize date/time input styles (#14931)
This PR adds some additional styles to Preflight to normalize a bunch of inconsistencies in date/time inputs across browsers. The main motivation for this is to remove these insane classes we have to add in Catalyst: ```html <input type="date" class="[&::-webkit-datetime-edit-fields-wrapper]:p-0 [&::-webkit-date-and-time-value]:min-h-[1.5em] [&::-webkit-datetime-edit]:inline-flex [&::-webkit-datetime-edit]:p-0 [&::-webkit-datetime-edit-year-field]:p-0 [&::-webkit-datetime-edit-month-field]:p-0 [&::-webkit-datetime-edit-day-field]:p-0 [&::-webkit-datetime-edit-hour-field]:p-0 [&::-webkit-datetime-edit-minute-field]:p-0 [&::-webkit-datetime-edit-second-field]:p-0 [&::-webkit-datetime-edit-millisecond-field]:p-0 [&::-webkit-datetime-edit-meridiem-field]:p-0"/> ``` With these normalizations, changing things like padding, display type, etc. gives consistent results (at least as consistent as is actually possible) across all browsers. --- **Make text alignment work on iOS Safari** <kbd><img width="418" alt="iOS Safari text alignment" src="https://github.com/user-attachments/assets/0ff792b2-1f3a-40c6-9185-6bd076c8715d"></kbd> --- **Don't shrink date inputs on iOS Safari when there is no selected value** <kbd><img width="409" alt="ioS Safari no input" src="https://github.com/user-attachments/assets/a8e69af7-3f0c-4d1d-b7a0-10355a5d3907"></kbd> --- **Fix padding in macOS Safari** <kbd><img width="717" alt="MacOS Safari" src="https://github.com/user-attachments/assets/5ea19b66-2dec-46e2-a386-d61bd5b8517a"></kbd> --------- Co-authored-by: Adam Wathan <4323180+adamwathan@users.noreply.github.com>
1 parent 56288a3 commit 5da6968

File tree

3 files changed

+82
-0
lines changed

3 files changed

+82
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313
- Add `svh`, `dvh`, `svw`, `dvw`, and `auto` values to all width/height/size utilities ([#14857](https://github.com/tailwindlabs/tailwindcss/pull/14857))
1414
- Add new `**` variant ([#14903](https://github.com/tailwindlabs/tailwindcss/pull/14903))
1515
- Process `<style>` blocks inside Svelte files when using the Vite extension ([#14151](https://github.com/tailwindlabs/tailwindcss/pull/14151))
16+
- Normalize date/time input styles in Preflight ([#14931](https://github.com/tailwindlabs/tailwindcss/pull/14931))
1617
- _Upgrade (experimental)_: Migrate `grid-cols-[subgrid]` and `grid-rows-[subgrid]` to `grid-cols-subgrid` and `grid-rows-subgrid` ([#14840](https://github.com/tailwindlabs/tailwindcss/pull/14840))
1718
- _Upgrade (experimental)_: Support migrating projects with multiple config files ([#14863](https://github.com/tailwindlabs/tailwindcss/pull/14863))
1819
- _Upgrade (experimental)_: Rename `shadow` to `shadow-sm`, `shadow-sm` to `shadow-xs`, and `shadow-xs` to `shadow-2xs` ([#14875](https://github.com/tailwindlabs/tailwindcss/pull/14875))

packages/@tailwindcss-postcss/src/__snapshots__/index.test.ts.snap

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,55 @@ exports[`\`@import 'tailwindcss'\` is replaced with the generated CSS 1`] = `
511511
-webkit-appearance: none;
512512
}
513513
514+
::-webkit-date-and-time-value {
515+
text-align: inherit;
516+
min-height: 1lh;
517+
}
518+
519+
::-webkit-datetime-edit {
520+
display: inline-flex;
521+
}
522+
523+
::-webkit-datetime-edit {
524+
padding: 0;
525+
}
526+
527+
::-webkit-datetime-edit-year-field {
528+
padding: 0;
529+
}
530+
531+
::-webkit-datetime-edit-month-field {
532+
padding: 0;
533+
}
534+
535+
::-webkit-datetime-edit-day-field {
536+
padding: 0;
537+
}
538+
539+
::-webkit-datetime-edit-hour-field {
540+
padding: 0;
541+
}
542+
543+
::-webkit-datetime-edit-minute-field {
544+
padding: 0;
545+
}
546+
547+
::-webkit-datetime-edit-second-field {
548+
padding: 0;
549+
}
550+
551+
::-webkit-datetime-edit-millisecond-field {
552+
padding: 0;
553+
}
554+
555+
::-webkit-datetime-edit-meridiem-field {
556+
padding: 0;
557+
}
558+
559+
::-webkit-datetime-edit-fields-wrapper {
560+
padding: 0;
561+
}
562+
514563
summary {
515564
display: list-item;
516565
}

packages/tailwindcss/preflight.css

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,38 @@ progress {
244244
-webkit-appearance: none;
245245
}
246246

247+
/*
248+
1. Ensure date/time inputs have the same height when empty in iOS Safari.
249+
2. Ensure text alignment can be changed on date/time inputs in iOS Safari.
250+
*/
251+
::-webkit-date-and-time-value {
252+
min-height: 1lh; /* 1 */
253+
text-align: inherit; /* 2 */
254+
}
255+
256+
/*
257+
Prevent height from changing on date/time inputs in macOS Safari when the input is set to `display: block`.
258+
*/
259+
::-webkit-datetime-edit {
260+
display: inline-flex;
261+
}
262+
263+
/*
264+
Remove excess padding from pseudo-elements in date/time inputs to ensure consistent height across browsers.
265+
*/
266+
::-webkit-datetime-edit,
267+
::-webkit-datetime-edit-year-field,
268+
::-webkit-datetime-edit-month-field,
269+
::-webkit-datetime-edit-day-field,
270+
::-webkit-datetime-edit-hour-field,
271+
::-webkit-datetime-edit-minute-field,
272+
::-webkit-datetime-edit-second-field,
273+
::-webkit-datetime-edit-millisecond-field,
274+
::-webkit-datetime-edit-meridiem-field,
275+
::-webkit-datetime-edit-fields-wrapper {
276+
padding: 0;
277+
}
278+
247279
/*
248280
Add the correct display in Chrome and Safari.
249281
*/

0 commit comments

Comments
 (0)