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

use a tag instead of abbr tag for search-choice-close #2726

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions coffee/chosen.jquery.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ class Chosen extends AbstractChosen
this.activate_field()

container_mouseup: (evt) ->
this.results_reset(evt) if evt.target.nodeName is "ABBR" and not @is_disabled
if not @is_disabled and @allow_single_deselect and $(evt.target).hasClass('search-choice-close')
this.results_reset(evt)

search_results_mousewheel: (evt) ->
delta = evt.originalEvent.deltaY or -evt.originalEvent.wheelDelta or evt.originalEvent.detail if evt.originalEvent
Expand Down Expand Up @@ -331,7 +332,7 @@ class Chosen extends AbstractChosen

results_reset_cleanup: ->
@current_selectedIndex = @form_field.selectedIndex
@selected_item.find("abbr").remove()
@selected_item.find('.search-choice-close').remove()

result_select: (evt) ->
if @result_highlight
Expand Down Expand Up @@ -402,8 +403,9 @@ class Chosen extends AbstractChosen

single_deselect_control_build: ->
return unless @allow_single_deselect
@selected_item.find("span").first().after "<abbr class=\"search-choice-close\"></abbr>" unless @selected_item.find("abbr").length
@selected_item.addClass("chosen-single-with-deselect")
unless @selected_item.find('.search-choice-close').length
@selected_item.find('span').first().after '<a class="search-choice-close"></a>'
@selected_item.addClass('chosen-single-with-deselect')

get_search_field_value: ->
@search_field.val()
Expand Down
9 changes: 5 additions & 4 deletions coffee/chosen.proto.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class @Chosen extends AbstractChosen

if @is_multiple
@search_choices.stopObserving()
@container.select(".search-choice-close").each (choice) ->
@container.select('.search-choice-close').each (choice) ->
choice.stopObserving()
else
@selected_item.stopObserving()
Expand Down Expand Up @@ -322,7 +322,7 @@ class @Chosen extends AbstractChosen

results_reset_cleanup: ->
@current_selectedIndex = @form_field.selectedIndex
deselect_trigger = @selected_item.down("abbr")
deselect_trigger = @selected_item.down('.search-choice-close')
deselect_trigger.remove() if(deselect_trigger)

result_select: (evt) ->
Expand Down Expand Up @@ -392,8 +392,9 @@ class @Chosen extends AbstractChosen

single_deselect_control_build: ->
return unless @allow_single_deselect
@selected_item.down("span").insert { after: "<abbr class=\"search-choice-close\"></abbr>" } unless @selected_item.down("abbr")
@selected_item.addClassName("chosen-single-with-deselect")
unless @selected_item.down('.search-choice-close')
@selected_item.down('span').insert { after: '<a class="search-choice-close"></a>' }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as there is no href, this won't get a pointer cursor in a cross-browser way (and browsers not showing it are perfectly fine according to the spec)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 28-30 of sass/chosen.scss force a cursor to all links within .chosen-container, but I agree that no href is less semantic.

Copy link
Collaborator

@stof stof Oct 17, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

proper semantic would probably be a <button type="button"> rather than a <a> btw.

@selected_item.addClassName('chosen-single-with-deselect')

get_search_field_value: ->
@search_field.value
Expand Down
8 changes: 4 additions & 4 deletions sass/chosen.scss
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ $chosen-sprite-retina: url('[email protected]') !default;
.chosen-single-with-deselect span {
margin-right: 38px;
}
.chosen-single abbr {
.chosen-single .search-choice-close {
position: absolute;
top: 6px;
right: 26px;
Expand All @@ -92,7 +92,7 @@ $chosen-sprite-retina: url('[email protected]') !default;
background-position: -42px -10px;
}
}
&.chosen-disabled .chosen-single abbr:hover {
&.chosen-disabled .chosen-single .search-choice-close:hover {
background-position: -42px -10px;
}
.chosen-single div {
Expand Down Expand Up @@ -355,7 +355,7 @@ $chosen-sprite-retina: url('[email protected]') !default;
right: auto;
left: 3px;
}
.chosen-single abbr {
.chosen-single .search-choice-close {
right: auto;
left: 26px;
}
Expand Down Expand Up @@ -410,7 +410,7 @@ $chosen-sprite-retina: url('[email protected]') !default;
/* @group Retina compatibility */
@media only screen and (-webkit-min-device-pixel-ratio: 1.5), only screen and (min-resolution: 144dpi), only screen and (min-resolution: 1.5dppx) {
.chosen-rtl .chosen-search input[type="text"],
.chosen-container-single .chosen-single abbr,
.chosen-container-single .chosen-single .search-choice-close,
.chosen-container-single .chosen-single div b,
.chosen-container-single .chosen-search input[type="text"],
.chosen-container-multi .chosen-choices .search-choice .search-choice-close,
Expand Down