Skip to content

v4 [hidden] attribute #17169

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

Closed
CoralSilver opened this issue Aug 20, 2015 · 19 comments
Closed

v4 [hidden] attribute #17169

CoralSilver opened this issue Aug 20, 2015 · 19 comments
Assignees

Comments

@CoralSilver
Copy link

The hidden attribute isn't supported in IE9 or 10. The comments say // Always hide an element with the hidden HTML attribute (from PureCSS). (instead of the old hidden class), but PureCSS includes a .hidden class along with the attribute.

@kkirsche
Copy link
Contributor

For any unsupported browser you can easily add support by just including the following CSS:

[hidden] { display: none; }

This will work back to IE6, which doesn’t support the attribute selector.

In other words, basically: https://github.com/twbs/bootstrap/blob/v4-dev/scss/_utilities.scss#L35

With that said, the workaround is not universal as it only patches attribute behavior to sort of mimic property behavior. I personally don't see any benefit in having a class for this as well.

@cvrebert
Copy link
Collaborator

Closing per @kkirsche's comment.

@mdo
Copy link
Member

mdo commented Aug 23, 2015

Mentioned some of this in the docs in cf7819d, FYI.

@CoralSilver
Copy link
Author

Thanks @kkirsche. So declaring display: none on the hidden attribute will patch default the attribute behavior. But the docs http://v4-alpha.getbootstrap.com/components/utilities/ say .hidden was removed due to conflicts with jQuery’s hide() function. [hidden] is set to display: none !important. What is the .hide() conflict? There is a conflict with .show(), since jQuery .show() doesn't use !important. So won't there still be the same jQuery conflict? Do people use .addClass() and .removeClass() now to get around it? Just trying to understand how this fixes this. Isn't toggling classes (attributes in this case) better practice than show and hide, or not ?

@kkirsche
Copy link
Contributor

@CoralSilver in regards to why it was removed and conflicts I would need to defer to @mdo / @cvrebert and the rest of the team as that's not an aspect I am familiar with. Sorry!

@hnrch02
Copy link
Collaborator

hnrch02 commented Aug 23, 2015

#9237 & #9881 talked about removing !important from hidden, I don't know where we stand on this now tho, @mdo?

@mdo
Copy link
Member

mdo commented Aug 23, 2015

Unsure of the feasibility honestly, we'll have to check it out.

@CoralSilver
Copy link
Author

Couldn't you remove !important if hidden was at the end of the stylesheet to override previous display: block? But then, this wouldn't work with any custom styles declared afterwards with display: block.

@cvrebert
Copy link
Collaborator

So, the two changes were made separately and not considered together.
(1) We removed .hidden because folks couldn't use it in combination with jQuery's very popular show()/hide() methods.
(2) We added [hidden] {display:none !important;} because the default HTML semantics for the hidden attribute (equivalent to [hidden] {display:none;}) kinda suck. For example, given:

<div class="x">Foo</div>
<div class="x" hidden>Bar</div>
.x {
  display: inline-block;
}

both "Foo" and "Bar" will be visible. This can be corrected by making the display:none be !important. Why HTML doesn't define [hidden] to be super-important in the first place is beyond me.

@cvrebert
Copy link
Collaborator

Isn't toggling classes (attributes in this case) better practice than show and hide, or not ?

Arguably yes, particularly considering the changes coming in jQuery 3.0 (see the "Simplified .show() and .hide() methods" section).

@CoralSilver
Copy link
Author

Yeah, that is weird that [hidden] isn't important. So shouldn't it be mentioned in the docs that [hidden] won't work with show() and hide() either, and one shouldn't be using those functions to toggle visibility at all, especially given the coming changes you mentioned? So .hidden could still exist in that case? Or is there some semantic or accessibility reason to use the attribute instead?

@cvrebert
Copy link
Collaborator

It's certainly more semantic. The semantic meaning of [hidden] is defined by the HTML5 spec, whereas .hidden is just another class as far as the browser and assistive technologies are concerned. And there's no consensus on what to name the class; libraries variously use .hide, .hidden, .invisible, etc.

Yeah, the interaction with jQuery could stand to be documented.

@CoralSilver
Copy link
Author

I think mentioning in the docs that .hidden was swapped for [hidden] because it is more semantic, rather than because of the show() hide() conflict (with a mention of the proper way to deal with it in jQuery), would definitely make the change more understandable.

@cvrebert cvrebert self-assigned this Aug 24, 2015
@cvrebert cvrebert added docs and removed css labels Aug 24, 2015
@cvrebert cvrebert added this to the v4.0.0-alpha.2 milestone Aug 24, 2015
@cvrebert cvrebert reopened this Aug 24, 2015
@CoralSilver
Copy link
Author

As .hidden wasn't deprecated in the last version, I would consider leaving it in (with a deprecation notice), so users that were using it with removeClass() will have time to switch over to removeAttr() (and not be forced to). Doesn't seem like it would make much difference with assistive technologies, no? They are already going to skip over something display: none.

@kkirsche
Copy link
Contributor

@CoralSilver there's no reason for us to deprecate it in my opinion. V4 is a major update and as such we should probably not deprecate things as this is our chance per semantic versioning to make non backwards compatible changes. Keeping it as deprecated will keep it until V5 which while small starts this type of questioning about any and all classes which I think the core team would want to avoid. X-Ref: #17240

@CoralSilver
Copy link
Author

Makes sense. Thanks.

azmenak pushed a commit to azmenak/bootstrap that referenced this issue Aug 27, 2015
@mdo
Copy link
Member

mdo commented Sep 2, 2015

We all good here or is there something else to tackle yet?

@cvrebert
Copy link
Collaborator

cvrebert commented Sep 2, 2015

@mdo I got this.

cvrebert added a commit that referenced this issue Sep 24, 2015
@cvrebert
Copy link
Collaborator

Resolved by #17689.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants