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

Reset dialog element styles #11069

Merged
merged 5 commits into from Apr 28, 2023
Merged

Reset dialog element styles #11069

merged 5 commits into from Apr 28, 2023

Conversation

eranhirsch
Copy link
Contributor

@eranhirsch eranhirsch commented Apr 23, 2023

The HTML dialog element has a lot of default styling coming from the user agent (chromium, mozilla, looks like safari don't style dialogs at all).

I noticed this when trying to debug why I was getting a 16px padding regardless of what my styling was. Except padding it looks like there are also styles for colors and a border. This feels like a bug as I'm used to tailwind's preflight providing a pretty good "blank slate" of expected styling. Some of the other styles (like the positioning) seem reasonable as they are pretty close to what I came up defining by myself for the dialog.

margin: 0;
border: none;
padding: 0;
background: transparent;

Choose a reason for hiding this comment

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

One more nit here - with a double space before transparent

src/css/preflight.css Outdated Show resolved Hide resolved
@eranhirsch
Copy link
Contributor Author

eranhirsch commented Apr 24, 2023

How should we handle the remaining properties on dialog? Should we also reset:

  • position
  • display (mozilla)
  • left, right (chromium), inset-inline-start, inset-inline-end (mozilla)
  • width, height

@adamwathan
Copy link
Member

adamwathan commented Apr 28, 2023

Thanks for the PR! Personally I think this reset can be simplified to just this:

dialog {
  padding: 0;
}
  • We shouldn't reset border as Preflight already handles that so the border on dialogs is already removed in Tailwind, and resetting it this way means adding the border utility to dialogs won't work.
  • The user agent margin styles are just for centering the dialog on the screen, and aren't absolute values like 10px that might cause you to accidentally deviate from your spacing scale. So I'm fine with just leaving this set to auto rather than be overly aggressive with resetting it.
  • Since dialogs are intended to sort of render "on top" of other stuff I don't think it's totally surprising that they don't inherit color (probably why the user agent explicitly sets it), so I think it's okay that we leave it alone too. You might render the same dialog component from within different parent elements and expect the dialog to always have the same colors in both situations, so I think people will already be explicit about what text color they want their dialogs to use.
  • Similar story for background-color — I think since all browsers reliably define this as the same value (the canvas system color) I'd rather just leave this alone. People are going to override it to the color they need, and I can't think of how changing it to transparent actually does anyone any favors.

Happy to merge this if it can be rebased on top of the current conflicts and simplified to just the padding reset 👍

@RobinMalfait
Copy link
Contributor

I rebased this PR on master so you don't have to worry about that 👍

@thecrypticace thecrypticace changed the title Reset dialog element sytles Reset dialog element styles Apr 28, 2023
@thecrypticace thecrypticace changed the base branch from master to 3.3 April 28, 2023 16:22
@thecrypticace thecrypticace merged commit 7b3fe8d into tailwindlabs:3.3 Apr 28, 2023
21 checks passed
@thecrypticace
Copy link
Contributor

Thanks! I've updated it to just the padding reset and merged this in. It'll be available in our next tagged release. Appreciate it! ✨

@lorenzolewis
Copy link

I just ran into an issue with inset-inline-start: 0px; and inset-inline-end: 0px; being the defaults in Safari and causing some issues (such as relative positioning with right: 0;). This might be one to consider adding into the reset.

More than happy to file an issue for this one if needed.

thecrypticace added a commit that referenced this pull request Jul 13, 2023
* disable useragent styling for dialog

* nits

* Update src/css/preflight.css

* Simplify dialog reset

We don’t want to reset everything here. Just the padding should be enough.

* Update test

---------

Co-authored-by: Robin Malfait <malfait.robin@gmail.com>
Co-authored-by: Jordan Pittman <jordan@cryptica.me>
thecrypticace added a commit that referenced this pull request Jul 13, 2023
* disable useragent styling for dialog

* nits

* Update src/css/preflight.css

* Simplify dialog reset

We don’t want to reset everything here. Just the padding should be enough.

* Update test

---------

Co-authored-by: Robin Malfait <malfait.robin@gmail.com>
Co-authored-by: Jordan Pittman <jordan@cryptica.me>
thecrypticace added a commit that referenced this pull request Jul 13, 2023
* disable useragent styling for dialog

* nits

* Update src/css/preflight.css

* Simplify dialog reset

We don’t want to reset everything here. Just the padding should be enough.

* Update test

---------

Co-authored-by: Robin Malfait <malfait.robin@gmail.com>
Co-authored-by: Jordan Pittman <jordan@cryptica.me>
AlexTMjugador added a commit to AlexTMjugador/Home that referenced this pull request Jul 15, 2023
Tailwind 3.3.3 introduced a change by which the default user agent
dialog element padding is reset to none: tailwindlabs/tailwindcss#11069

This caused the dialog to consistently not display as intended accross
browsers. To fix that, let's manually set the padding to the one we
expected.
AlexTMjugador added a commit to AlexTMjugador/Home that referenced this pull request Feb 20, 2024
Tailwind 3.3.3 introduced a change by which the default user agent
dialog element padding is reset to none: tailwindlabs/tailwindcss#11069

This caused the dialog to consistently not display as intended accross
browsers. To fix that, let's manually set the padding to the one we
expected.
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

6 participants