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

Proposal: Allow adding separator rows to <select> boxes using <hr> #3410

Closed
a2sheppy opened this issue Jan 26, 2018 · 12 comments · Fixed by #9124
Closed

Proposal: Allow adding separator rows to <select> boxes using <hr> #3410

a2sheppy opened this issue Jan 26, 2018 · 12 comments · Fixed by #9124
Labels
addition/proposal New features or enhancements topic: forms

Comments

@a2sheppy
Copy link

There is no standard way to create a proper separator or dividing line within the box created using <select>. Currently, the most common solution is to just put some hyphens or emdashes in an <option> with the disabled attribute set. This doesn't actually look very good at all, and is not semantically accurate.

There's already a perfectly good element for creating horizontal dividing lines in HTML: the <hr> element. This should be allowed in the context of a <select> element in order to create separator rows.

This would let you then create a separator using <hr> within the <select>, like:

<select id="devicelist">
    <option value="none">None</option>
    <hr/>
    <option value="1903177618651917">Internal microphone</option>
</select>

In this situation, the <hr> is interpreted as a separator row and treated as such, rather than as a selectable option (since it's not an <option> element.

I've also filed this on the W3C spec: w3c/html#1156

@domenic
Copy link
Member

domenic commented Jan 26, 2018

Hmm. I'm not sure this is semantically accurate either; it feels more like a stylistic issue that you want to separate some options from each other. Do you think it'd make more sense to improve styling of option elements to e.g. allow you to add a bottom-margin or border for such separation purposes?

Anyway, this particular proposal is not possible, since the HTML parser discards the <hr> (and changing the parser is not generally done without extraordinarily good reason). See http://software.hixie.ch/utilities/js/live-dom-viewer/?saved=5769 for a demo.

If we were to try to solve this at a semantic level, we'd probably want to do it using some modification of optgroup, which is an existing semantic mechanism for grouping options.

@domenic domenic added addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest topic: forms labels Jan 26, 2018
@Nadya678
Copy link

Nadya678 commented Jan 26, 2018

The better solution is to add the full possibility to style the <select/>
w3c/csswg-drafts#2013

Then you will be able use border, margin and padding for the same effect or select option::after. The <hr/> in this case doesn't change theme of the document. Not semantic use.

I want to add not only lines between options but also change the frame of ::dropdown-list of the <select/>

@a2sheppy
Copy link
Author

a2sheppy commented Jan 26, 2018

@domenic - That's a good point. That was actually going to be my follow-up proposal if this one didn't fly, to propose an amendment to <optgroup> to allow it to be used to create separators rather than named groups.

Since currently the label attribute is mandatory on <optgroup>, the obvious approach would be to simply make it optional, in which case the group is an unnamed one, separated from the previous and next groups (as applicable) by dividing lines or other platform-appropriate technique.

You could of course go a step farther and add, say, an optional type attribute that could override the browser/platform-defined behavior; something like

<optgroup type="divider" disabled>
    ... options ...
</optgroup>
<optgroup type="spacer" disabled>
    ... options ...
</optgroup>

The type would be used to indicate the type of separation above and below. In cases of conflict (such as above, where the first group wants "divider" and the second "spacer"), the top group wins.

@gsnedders
Copy link
Member

https://codepen.io/tigt/post/separators-inside-the-select-element seems to have discovered this actually exists today in Blink and WebKit; this seems to date from 2005 (WebKit/WebKit@23dccec), though the parser side got broken at some point (probably with the HTML parser rewrite?), so currently it only works with DOM manipulation (and presumably XHTML? not tested).

@othermaciej
Copy link

To some extent separation of groups of options in a menu is semantic, not just style. When separators are used in native system menus, they are often used between groups of related items. So in that sense it's similar in meaning <optgroup>, except without a name. Based on that, I think either unnamed <optgroup> or <hr> as a way to get a separator would be better than using a fully general styling mechanism to add a margin or separator line to a specific item. Even with custom styling, adding style to an <hr> or a nameless <optgroup> would better express what is going on.

@zcorpan
Copy link
Member

zcorpan commented Aug 11, 2022

Indeed this is still supported in WebKit and Blink for both drop-down select and listbox select (<select size=4>). http://software.hixie.ch/utilities/js/live-dom-viewer/saved/10552

@whatwg/html-parser Is there interest in changing the parser to allow <hr> in select? Including making it imply an </option> end tag. I think it should be OK security-wise as it's a void element select throws away most tags.

@domenic
Copy link
Member

domenic commented Aug 12, 2022

Note that it's not supported on Blink on Linux at least... I wonder about Windows.

@zcorpan
Copy link
Member

zcorpan commented Aug 12, 2022

OK. I made a clearer demo: http://software.hixie.ch/utilities/js/live-dom-viewer/saved/10554

Here's how it looks on macOS in Chrome:

The listbox has some spacing between the before options and the after options. The dropdown has a gray thin line between the before options and the after options.

Edge 103 on Windows 11 (tested with BrowserStack) also supports it:

The listbox has some spacing between the before options and the after options. The dropdown has a black thin line between the before options and the after options.

@domenic
Copy link
Member

domenic commented Aug 12, 2022

Oh, yeah, I'm seeing it on Linux Chrome now; thanks. Weird that it's a blank space as a separator in listbox select.

@zcorpan
Copy link
Member

zcorpan commented Aug 12, 2022

On iOS Safari it's not supported:

Listbox select is a one-line widget which opens a popup to select options. No extra separator for the hr element. Dropdown is not a full width popup but a dropdown anchored to the select widget. No extra separator for the hr element.

On Chrome on Android the hr becomes its own selectable option!:

Listbox select is a one-line widget that opens a popup to select options. There's a selectable option with no label between the before and after options. Dropdown select also opens a popup to select options. There's a selectable option with no label between the before and after options.

annevk added a commit that referenced this issue Apr 5, 2023
This is a long-standing WebKit feature that regressed as part of the standardized HTML parser effort. This suggests bringing it back with optional semantics, but a mandatory HTML parser change.

The HTML parser change is not expected to be significant for existing content or XSS. When the feature is correctly used it will also not hurt HTML parsers that have not yet incorporated the change. I.e., it should be fully backwards compatible.

Fixes #3410.
annevk added a commit that referenced this issue Apr 5, 2023
This is a long-standing WebKit feature that regressed as part of the standardized HTML parser effort. This suggests bringing it back with optional semantics, but a mandatory HTML parser change.

The HTML parser change is not expected to be significant for existing content or XSS. When the feature is correctly used it will also not hurt HTML parsers that have not yet incorporated the change. I.e., it should be fully backwards compatible.

Fixes #3410.
annevk added a commit that referenced this issue Apr 5, 2023
This is a long-standing WebKit feature that regressed as part of the standardized HTML parser effort. This suggests bringing it back with optional semantics, but a mandatory HTML parser change.

The HTML parser change is not expected to be significant for existing content or XSS. When the feature is correctly used it will also not hurt HTML parsers that have not yet incorporated the change. I.e., it should be fully backwards compatible.

Fixes #3410.
@zcorpan
Copy link
Member

zcorpan commented Apr 6, 2023

@annevk do you plan to add rendering support in iOS Safari?

@annevk
Copy link
Member

annevk commented Apr 6, 2023

I can't really speak to that. The feature is mostly optional, but can enrich the user experience when implemented and used.

annevk added a commit that referenced this issue May 2, 2023
This is a long-standing WebKit feature that regressed as part of the standardized HTML parser effort. This suggests bringing it back with optional semantics, but a mandatory HTML parser change.

The HTML parser change is not expected to be significant for existing content or XSS. When the feature is correctly used it will also not hurt HTML parsers that have not yet incorporated the change. I.e., it should be fully backwards compatible.

Tests: html5lib/html5lib-tests#167.

Fixes #3410.
@annevk annevk removed the needs implementer interest Moving the issue forward requires implementers to express interest label May 2, 2023
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this issue Aug 6, 2023
Upstream changes:
 https://github.com/sparklemotion/nokogiri/releases/tag/v1.15.3
 https://github.com/sparklemotion/nokogiri/releases/tag/v1.15.2
 https://github.com/sparklemotion/nokogiri/releases/tag/v1.15.1
 https://github.com/sparklemotion/nokogiri/releases/tag/v1.15.0

1.15.3 / 2023-07-05

Fixed

 * Passing an object that is not a kind of XML::Node as the first parameter to
   CDATA.new now raises a TypeError. Previously this would result in either a
   segfault (CRuby) or a Java exception (JRuby). [#2920]
 * Passing an object that is not a kind of XML::Node as the first parameter to
   Schema.from_document now raises a TypeError. Previously this would result
   in either a segfault (CRuby) or a Java exception (JRuby). [#2920]
 * [CRuby] Passing an object that is not a kind of XML::Node as the second
   parameter to Text.new now raises a TypeError. Previously this would result
   in a segfault. [#2920]
 * [CRuby] Replacing a node's children via methods like Node#inner_html=, #
   children=, and #replace no longer defensively dups the node's next sibling
   if it is a Text node. This behavior was originally adopted to work around
   libxml2's memory management (see #283 and #595) but should not have
   included operations involving xmlAddChild(). [#2916]
 * [JRuby] Fixed NPE when serializing an unparented HTML node. [#2559, #2895]
   (Thanks, @cbasguti!)

1.15.2 / 2023-05-24

Dependencies

 * [JRuby] Vendored org.nokogiri:nekodtd is updated to v0.1.11.noko2. This is
   functionally equivalent to v0.1.11.noko1 but restores support for Java 8.

Fixed

 * [JRuby] Java 8 support is restored, fixing a regression present in
   v1.14.0..v1.14.4 and v1.15.0..v1.15.1. [#2887]

1.15.1 / 2023-05-19

Dependencies

 * [CRuby] Vendored libxml2 is updated to v2.11.4 from v2.11.3. For details
   please see https://gitlab.gnome.org/GNOME/libxml2/-/releases/v2.11.4

Fixed

 * [CRuby] The libxml2 update fixes an encoding regression when push-parsing
   UTF-8 sequences. [#2882, upstream issue and commit]

1.15.0 / 2023-05-15

Notes

Ability to opt into system malloc and free

Since 2009, Nokogiri has configured libxml2 to use ruby_xmalloc et al for
memory management. This has provided benefits for memory management, but comes
with a performance penalty.

Users can now opt into using system malloc for libxml2 memory management by
setting an environment variable:

# "default" here means "libxml2's default" which is system malloc
NOKOGIRI_LIBXML_MEMORY_MANAGEMENT=default

Benchmarks show that this setting will significantly improve performance, but
be aware that the tradeoff may involve poorer memory management including
bloated heap sizes and/or OOM conditions.

You can read more about this in the decision record at adr/
2023-04-libxml-memory-management.md.

Dependencies

 * [CRuby] Vendored libxml2 is updated to v2.11.3 from v2.10.4. For details
   please see:
    + https://gitlab.gnome.org/GNOME/libxml2/-/releases/v2.11.0
    + https://gitlab.gnome.org/GNOME/libxml2/-/releases/v2.11.1
    + https://gitlab.gnome.org/GNOME/libxml2/-/releases/v2.11.2
    + https://gitlab.gnome.org/GNOME/libxml2/-/releases/v2.11.3
 * [CRuby] Vendored libxslt is updated to v1.1.38 from v1.1.37. For details
   please see:
    + https://gitlab.gnome.org/GNOME/libxslt/-/releases/v1.1.38

Added

 * Encoding objects may now be passed to serialization methods like #to_xml, #
   to_html, #serialize, and #write_to to specify the output encoding.
   Previously only encoding names (strings) were accepted. [#2774, #2798]
   (Thanks, @ellaklara!)
 * [CRuby] Users may opt into using system malloc for libxml2 memory
   management. For more detail, see note above or adr/
   2023-04-libxml-memory-management.md.

Changed

 * [CRuby] Schema.from_document now makes a defensive copy of the document if
   it has blank text nodes with Ruby objects instantiated for them. This
   prevents unsafe behavior in libxml2 from causing a segfault. There is a
   small performance cost, but we think this has the virtue of being "what the
   user meant" since modifying the original is surprising behavior for most
   users. Previously this was addressed in v1.10.9 by raising an exception.

Fixed

 * [CRuby] XSLT.transform now makes a defensive copy of the document if it has
   blank text nodes with Ruby objects instantiated for them and the template
   uses xsl:strip-spaces. This prevents unsafe behavior in libxslt from
   causing a segfault. There is a small performance cost, but we think this
   has the virtue of being "what the user meant" since modifying the original
   is surprising behavior for most users. Previously this would allow unsafe
   memory access and potentially segfault. [#2800]

Improved

 * Nokogiri::XML::Node::SaveOptions#inspect now shows the names of the options
   set in the bitmask, similar to ParseOptions. [#2767]
 * #inspect and pretty-printing are improved for AttributeDecl,
   ElementContent, ElementDecl, and EntityDecl.
 * [CRuby] The C extension now uses Ruby's TypedData API for managing all the
   libxml2 structs. Write barriers may improve GC performance in some extreme
   cases. [#2808] (Thanks, @etiennebarrie and @byroot!)
 * [CRuby] ObjectSpace.memsize_of reports a pretty good guess of memory usage
   when called on Nokogiri::XML::Document objects. [#2807] (Thanks,
   @etiennebarrie and @byroot!)
 * [CRuby] Users installing the "ruby" platform gem and compiling libxml2 and
   libxslt from source will now be using a modern config.guess and config.sub
   that supports new architectures like loongarch64. [#2831] (Thanks,
   @zhangwenlong8911!)
 * [CRuby] HTML5 parser:
    + adjusts the specified attributes, adding xlink:arcrole and removing
      xml:base [#2841, #2842]
    + allows <hr> in <select> [whatwg/html#3410, whatwg/html#9124]
 * [JRuby] Node#first_element_child now returns nil if there are only
   non-element children. Previously a null pointer exception was raised. [#
   2808, #2844]
 * Documentation for Nokogiri::XSLT now has usage examples including custom
   function handlers.

Deprecated

 * Passing a Nokogiri::XML::Node as the first parameter to CDATA.new is
   deprecated and will generate a warning. This parameter should be a kind of
   Nokogiri::XML::Document. This will become an error in a future version of
   Nokogiri.
 * Passing a Nokogiri::XML::Node as the first parameter to
   Schema.from_document is deprecated and will generate a warning. This
   parameter should be a kind of Nokogiri::XML::Document. This will become an
   error in a future version of Nokogiri.
 * Passing a Nokogiri::XML::Node as the second parameter to Text.new is
   deprecated and will generate a warning. This parameter should be a kind of
   Nokogiri::XML::Document. This will become an error in a future version of
   Nokogiri.
 * [CRuby] Calling a custom XPath function without the nokogiri namespace is
   deprecated and will generate a warning. Support for non-namespaced
   functions will be removed in a future version of Nokogiri. (Note that JRuby
   has never supported non-namespaced custom XPath functions.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addition/proposal New features or enhancements topic: forms
Development

Successfully merging a pull request may close this issue.

7 participants