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

Make styles optional? #14

Closed
Nettsentrisk opened this issue Nov 28, 2018 · 9 comments
Closed

Make styles optional? #14

Nettsentrisk opened this issue Nov 28, 2018 · 9 comments

Comments

@Nettsentrisk
Copy link

Nettsentrisk commented Nov 28, 2018

If you're handling styling of the summary elements on your own, there's no way to use this polyfill without it polluting your styles and requiring overriding them everywhere you intend to use your own styles.

Optimally the CSS for this package would be included separately, so you can import the styles into your stylesheet setup if you want. Either that or there should be two versions of the script, one without polyfilling styles, and one with.

An example: Bootstrap has set up their npm package so that you only get script when you import the script, and you have to import the styles separately if you want them: https://getbootstrap.com/docs/4.1/getting-started/webpack/

@javan
Copy link
Owner

javan commented Nov 28, 2018

The styles are only added to browsers that don't support <details> natively; hence, they're polyfilled.

For example, open data:text/html,%3Cdetails%3E%3Csummary%3Ehello%3C/summary%3E%3Cp%3Eworld%3C/p%3E%3C/details%3E in Safari or Chrome:

screen shot 2018-11-28 at 10 26 06 am

So you're always going to be overriding styles to customize their appearance. Either the browser's default styles or the polyfilled styles.

@javan javan closed this as completed Nov 28, 2018
@Nettsentrisk
Copy link
Author

Let me explain:

Let's say you are adding a pseudo-element to your summary elements to create a certain style, and you are styling away the default styles that the browser uses for this.

In order to override the styles that this package forces onto you when you use the script, you'll have to set display: none on the pseudo-element that is created through the package styles. However, that will remove all the custom pseudo-elements you've set up for all browsers, leading to have to override them again, which can't be done very easily due to the global nature of the included styles.

Splitting up the script and the styles like Bootstrap does lets the developer choose whether he wants the styles or not.

@javan
Copy link
Owner

javan commented Nov 28, 2018

In order to override the styles that this package forces onto you when you use the script, you'll have to set display: none on the pseudo-element that is created through the package styles.

You don't have to set display: none. Instead, override or reset the individual properties defined in the included styles:

details > summary::before {
content: "►";
padding-right: 0.3rem;
font-size: 0.6rem;
cursor: default;
}
details[open] > summary::before {
content: "▼";
}

To remove the triangles, for example:

details > summary::before {
  content: "" !important;
}
details[open] > summary::before { 
  content: "" !important; 
} 

Splitting up the script and the styles like Bootstrap does lets the developer choose whether he wants the styles or not.

Bootstrap is not a good comparison. It's a library with optional features. This is a polyfill that replicates an HTML standard as closely as possible.

@kleinfreund
Copy link
Contributor

@javan Setting content: "" doesn’t seem to be sufficient for resetting the styles in Edge. The padding is still visible and needs to be reset as well.

@javan
Copy link
Owner

javan commented Dec 4, 2018

Correct, that is how CSS works. I was just demonstrating how one might override some of the polyfill's styles for @Nettsentrisk, who thought it was impossible.

@Nettsentrisk
Copy link
Author

Impossible, no. Impractical, yes. This is what I said:

there's no way to use this polyfill without it polluting your styles and requiring overriding them everywhere you intend to use your own styles

As far as I'm aware, there is nothing in any spec that states that the summary element shall be styled in the manner being done with the built-in styles in this project. Polyfilling entails providing native functionality according to some existing spec. Including some arbitrary styling of an element is not part of polyfilling.

Therefore, the styling of the element via this package should be optional, because it's actually an optional styling beyond merely polyfilling the functionality of the element.

@muan
Copy link
Collaborator

muan commented Dec 4, 2018

There is suggested styling for the element in spec. A disclosure indicator is needed and not optional; unfortunately it hasn't been implemented uniformly. See:

While the exact implementation is being finalized, I think what this project currently does is reasonable and should stay.

@javan
Copy link
Owner

javan commented Dec 4, 2018

You also said:

In order to override the styles that this package forces onto you when you use the script, you'll have to set display: none on the pseudo-element

Which is not true so I took time out of my day to present a detailed example of why you don't have to set display: none.

Including some arbitrary styling of an element is not part of polyfilling.

They're not arbitrary by any means:

Example 1

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/details
screen shot 2018-12-04 at 9 44 23 am

Example 2

https://www.w3.org/TR/html5/interactive-elements.html#the-details-element
screen shot 2018-12-04 at 9 50 00 am


Therefore, the styling of the element via this package should be optional

You've used the word should several times now, and your tone has been generally unfriendly. I've chosen not to remove the default styles from this polyfill, which I provide for free on my own time. If you're not happy with that decision, fork it and move on.

@Nettsentrisk
Copy link
Author

Nettsentrisk commented Dec 4, 2018

As @muan has pointed out, the standards-based way of doing this is via the list-style property, not using a pseudo-element (or in the case of some Webkit browsers, the ::webkit-details-marker pseudo-element).

Introducing a pseudo-element means that you are interfering with the developer's choices/preferences to use the ::before pseudo-element for their own purposes completely unrelated to this polyfill or a "native" experience of it.

Therefore you would have to use a general style on all summary::before elements with display: none if you are not interested in this being displayed this way, which interferes with any existing summary::before styles you may have.

The arbitrary nature of the implementation is by doing it via pseudo-element, which is not based on any standard or spec, and which causes unforeseen and unneccessary problems.

If you allow people to use the style-portion of it separately, like Bootstrap does, then none of this would be an issue, because then it would be up to the developer whether or not they want to implement this non-standards based styling.

Obviously I could fork the project and do this on my own, but it would be a shame for this package to split off a lot of users simply because the author doesn't want to allow it to be used more flexibly. There are several of us now that have brought up this issue.

Why not make more people happy using your code than less? :)

Repository owner locked and limited conversation to collaborators Dec 4, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants