-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Indicator Display Style Variations #3142
Comments
Htmx inserts a few style rules by default for indicators: Lines 5020 to 5024 in 4177071
These rules just play with the As you said, is can be undesirable in "certain" scenarios, which is why htmx provides the
People might have very different styling desires, and I don't think it's relevant to embed more styling options into htmx itself, as it's not the library's goal. As you showed in your example above, you can quickly define custom CSS rules to customize the indicator's display. |
The reason I placed this request actually exresses my frustration exactly with this feature. It took me couple of years to realize I could create custom styling for this, by finding the above solution on the internet, and I avoided using this functionality all together. Providing sensible defaults for common use cases, like offering hx-indicator-block and hx-indicator-inline classes, wouldn't bloat the library but would drastically improve the developer experience. By providing these simple, out-of-the-box styling options, HTMX can empower developers to quickly achieve polished results. This change wouldn't restrict customization; it would simply provide a more welcoming and efficient experience for everyone, promoting more consistent and robust HTMX implementations. |
Here is the code that needs to be added. I was not able to do a PR, due to the tests requiring configuration and not able to run out of the box. `<style${nonceAttribute}>
.${htmx.config.indicatorClass} { opacity: 0; }
.${htmx.config.requestClass} .${htmx.config.indicatorClass} { opacity: 1; transition: opacity 200ms ease-in; }
.${htmx.config.requestClass}.${htmx.config.indicatorClass} { opacity: 1; transition: opacity 200ms ease-in; }
.${htmx.config.indicatorClass}-block { display: none; }
.${htmx.config.requestClass} .${htmx.config.indicatorClass}-block { display: block; }
.${htmx.config.requestClass}.${htmx.config.indicatorClass}-block { display: block; }
.${htmx.config.indicatorClass}-inline { display: none; }
.${htmx.config.requestClass} .${htmx.config.indicatorClass}-inline { display: inline-block; }
.${htmx.config.requestClass}.${htmx.config.indicatorClass}-inline { display: inline-block; }
</style>` |
The hx-indicator documentation gives examples of customizing the styling rules, and links to the Even if we added the classes you suggest, people would still need to stumble upon them in the docs to be able to know in the first place that they can use different default indicator classes. |
The hx-indicator page is the first a user sees, when starting with HTMX, and the classes would be available straight away to be used. For instance, at the moment I am adding the additional CSS lines on every page I use HTMX on. I do not add any other CSS. It feeld rather backward, adding 1 line for the HTMX cdn, and 10 lines for the inline-block styling for the hx-indicator, everywhere where one wants to use it. Adding the new classes would save all this hassle for hundred of developers. |
Well, personal opinion again, but I'd be against adding more lines to the core library for this, especially literal strings that cannot be minified.
I beg to differ on this one, sounds like a very specific situation to me to A) not include any CSS for a website, B) not want to add any CSS either to it, and C) would solely rely on a few CSS rules injected by a JS lib. |
@Telroshan if the problem is that 2 small lines of code will be added, then I would say the default style of the indicator to be changed to display:inline-block as it covers more use cases. |
I would agree with a better default, the issue is that for backwards compatibility reasons, we can't change defaults unless we release a major version (that's why we made htmx 2 for example, to introduce breaking changes) as this could break existing apps, and at this point it's very unlikely that htmx 3 would ever happen in the future. |
@Telroshan what would be the best way to resolve this? Is it by adding another class name? Or there might be a better solution. |
@lesichkovm are you able to host your own copy of HTMX (with your changes) instead of relying on a CDN? |
@geoffrey-eisenbarth I have no problem forking it, putting the changes in, and hosting it myself, but then how does it help the community? Does everyone have to do their own workaround, for a feature that has to be provided out of the box? Definitely the indicator using a visibility CSS selector was an oversight, which is normal for the proptype stage HTMX was in. So it is better to be fixed. Everyone knows its never easy to make such a change, but its always better to be done sooner, rather than later. As when its gets widely adopted, we will have to stick with it, even though it is not optimal. |
Not so sure about that, as stated above, Again my personal opinion, but as said above I think that if it has to be fixed, it'll be at the documentation level. If you hadn't stumbled upon the ability to customize indicators classes back then, then if that documentation had contained mentions to alternative indicator classes, you wouldn't have seen it either. And it's not your fault at all! That's why I'm saying that we need to fix this at the documentation level, to make sure newcomers don't miss out on this aspect. Documentation improvements are always welcome so if you feel it could be improved to avoid the frustration you experienced to other newcomers, either by rearranging, adding precisions, more examples, or whatever else you think is relevant, please feel free to do so! |
At the moment, the hx-indicator uses the visibility: hidden style. Unlike display: none, the visibility style maintains the element's width, which can be undesirable in certain scenarios. For instance, when used within buttons, the hidden indicator can still occupy space, affecting the button's appearance.
To address this, many developers resort to additional styling like this:
This approach works, but it can be cumbersome and add unnecessary complexity to your stylesheets.
I propose creating variations of the hx-indicator class to offer more flexibility:
This approach provides developers with more control over the indicator's display behavior, making it easier to integrate smoothly into various design contexts.
The text was updated successfully, but these errors were encountered: