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

Add scrollbar-width utilities #14183

Open
wants to merge 1 commit into
base: next
Choose a base branch
from

Conversation

lukewarlow
Copy link
Contributor

@lukewarlow lukewarlow commented Aug 13, 2024

What?

This PR adds 3 new utilities for styling the width of scrollbars.

scrollbar-width-auto - For resetting a scrollbar to full-width, useful for overriding the other two*.

scrollbar-thin - For setting the scrollbar-width property to thin, which normally results in a thinner scrollbar.

scrollbar-none - For setting the scrollbar-width property to none, which hides the scrollbar. This utility also includes a fallback to the legacy ::-webkit-scrollbar { display: none; }. Read about ::-webkit-scrollbar here.

    • I think scrollbar-none might take precendence over scrollbar-width-auto in WebKit (and chromium) browsers because the ::-webkit-scrollbar rule beats the scrollbar-width: auto rule.

Why?

Styling of scrollbars is a long requested feature. See https://github.com/tailwindlabs/tailwindcss/discussions?discussions_q=is%3Aopen+scrollbar for a list of discussions requesting utilities for scrollbar styling.

This PR would be an initial step in that direction allowing authors to hide scrollbars (while maintaining the ability to scroll) in UIs where that is needed.

The naming of scrollbar-width-auto is different because the auto value is used across 3 separate scrollbar properties (scrollbar-width, scrollbar-color and scrollbar-gutter. We could keep this inconsistency, change all values to be scrollbar-width-X, or we could drop the auto utility?

scrollbar-width has 75% support according to caniuse. Though this and scrollbar-gutter are part of Interop 2024 and both the scrollbar-width property and scrollbar-gutter shipped in Safari 18.2.

Due to the currently limited support mentioned above the scrollbar-none utility includes the ::-webkit-scrollbar fallback to maximise Browser compatability including the fallback brings that utility up to 100% of the supported Tailwind browsers.

See #5732 for a previous attempt at contributing this. No worries if the Tailwind team still aren't ready for scrollbar styling, but given the change in browser support status of this API, I thought I'd give it another go.

If the team are open to these contributions I'd happily also open one for scrollbar-gutter and even scrollbar-color (might need some API discussions but see #5751 for an initial idea)

@lukewarlow lukewarlow changed the title Add scrollbar-none, scrollbar-thin, scrollbar-width-auto utilities Add scrollbar-width utilities Aug 13, 2024
@RobinMalfait RobinMalfait requested a review from a team as a code owner November 21, 2024 13:40
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.

1 participant