Skip to content

Commit

Permalink
feat(search): support remove icon
Browse files Browse the repository at this point in the history
Support remove icon for search module similar to dropdown module
Either via separate remove icon or by using a native input[type="search"] element

Sidenote
I party reused code which was already implemented in 2015 but removed again (by accident or intentionally , only the original authors knows...)
That's why i also removed the left dead css code for selection search which never made it into any release and wasn't ever documented.
  • Loading branch information
lubber-de authored Dec 22, 2024
1 parent 16a9552 commit 22d2d0d
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 38 deletions.
11 changes: 11 additions & 0 deletions src/definitions/modules/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
.on('mousedown' + eventNamespace, selector.results, module.event.result.mousedown)
.on('mouseup' + eventNamespace, selector.results, module.event.result.mouseup)
.on('click' + eventNamespace, selector.result, module.event.result.click)
.on('click' + eventNamespace, selector.remove, module.event.remove.click)
;
},
},
Expand Down Expand Up @@ -201,6 +202,12 @@
callback();
}
},
remove: {
click: function () {
module.clear.value();
$prompt.trigger('focus');
},
},
result: {
mousedown: function () {
module.resultsClicked = true;
Expand Down Expand Up @@ -837,6 +844,9 @@
$module.data(metadata.cache, cache);
}
},
value: function () {
module.set.value('');
},
},

read: {
Expand Down Expand Up @@ -1456,6 +1466,7 @@

selector: {
prompt: '.prompt',
remove: '> .icon.input > .remove.icon',
searchButton: '.search.button',
results: '.results',
message: '.results > .message',
Expand Down
55 changes: 32 additions & 23 deletions src/definitions/modules/search.less
Original file line number Diff line number Diff line change
Expand Up @@ -271,37 +271,46 @@
Types
*******************************/

& when (@variationSearchSelection) {
& when (@variationSearchClear) {
/* --------------
Selection
Clear Icon
--------------- */

.ui.search.selection .prompt {
border-radius: @selectionPromptBorderRadius;
.ui.search > .icon.input > .remove.icon {
pointer-events: all;
transition: @clearableIconTransition;
cursor: pointer;
opacity: @clearableIconOpacity;
&:hover {
opacity: @clearableIconHoverOpacity;
}
}

/* Remove input */
.ui.search.selection > .icon.input > .remove.icon {
pointer-events: none;
position: absolute;
left: auto;
opacity: 0;
color: @selectionCloseIconColor;
top: @selectionCloseTop;
right: @selectionCloseRight;
transition: @selectionCloseTransition;
.ui.search > .icon.input:not([class*="left icon"]) > .icon ~ .remove.icon {
right: @clearableIconInputRight;
}
.ui.search.selection > .icon.input > .active.remove.icon {
.ui.search input[type="search"]::-webkit-search-cancel-button {
-webkit-appearance: none;
cursor: pointer;
opacity: @selectionCloseIconOpacity;
pointer-events: auto;
transition: @clearableIconTransition;
opacity: @clearableIconOpacity;
background: @clearableIconBackground;
height: @clearableIconHeight;
width: @clearableIconWidth;
&:hover {
opacity: @clearableIconHoverOpacity;
}
}
& when (@variationSearchLoading) {
.ui.loading.search input[type="search"]::-webkit-search-cancel-button {
display: none;
}
}
.ui.search.selection > .icon.input:not([class*="left icon"]) > .icon ~ .remove.icon {
right: @selectionCloseIconInputRight;
.ui.search > .icon.input > input:placeholder-shown ~ .remove.icon,
.ui.search.loading > .icon.input > .remove.icon {
display: none;
}
.ui.search.selection > .icon.input > .remove.icon:hover {
opacity: @selectionCloseIconHoverOpacity;
color: @selectionCloseIconHoverColor;
.ui.search > .icon.input > input:-ms-input-placeholder ~ .remove.icon when (@supportIE) {
display: none;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/themes/default/globals/variation.variables
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@

/* Search */
@variationSearchDisabled: true;
@variationSearchSelection: true;
@variationSearchClear: true;
@variationSearchCategory: true;
@variationSearchHorizontalCategory: true;
@variationSearchLoading: true;
Expand Down
28 changes: 14 additions & 14 deletions src/themes/default/modules/search.variables
Original file line number Diff line number Diff line change
Expand Up @@ -126,20 +126,20 @@
Types
*******************************/

/* Selection */
@selectionPromptBorderRadius: @defaultBorderRadius;

@selectionCloseTop: 0;
@selectionCloseTransition:
color @defaultDuration @defaultEasing,
opacity @defaultDuration @defaultEasing;
@selectionCloseRight: 0;
@selectionCloseIconOpacity: 0.8;
@selectionCloseIconColor: "";
@selectionCloseIconHoverOpacity: 1;
@selectionCloseIconHoverColor: @red;

@selectionCloseIconInputRight: 1.85714em;
/* Clearable */
@clearableIconTransition: opacity @defaultDuration @defaultEasing;
@clearableIconOpacity: 0.6;
@clearableIconHoverOpacity: 1;
@clearableIconWidth: 1em;
@clearableIconHeight: @clearableIconWidth;

@clearableIconInputRight: 1.85714em;

/*
* Times icon taken from Font Awesome Free 5.15.4 by @fontawesome [https://fontawesome.com]
* License - https://fontawesome.com/license/free
*/
@clearableIconBackground: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 352 512'%3E%3Cpath d='M242.7 256l100.1-100.1c12.3-12.3 12.3-32.2 0-44.5l-22.2-22.2c-12.3-12.3-32.2-12.3-44.5 0L176 189.3 75.9 89.2c-12.3-12.3-32.2-12.3-44.5 0L9.2 111.5c-12.3 12.3-12.3 32.2 0 44.5L109.3 256 9.2 356.1c-12.3 12.3-12.3 32.2 0 44.5l22.2 22.2c12.3 12.3 32.2 12.3 44.5 0L176 322.7l100.1 100.1c12.3 12.3 32.2 12.3 44.5 0l22.2-22.2c12.3-12.3 12.3-32.2 0-44.5L242.7 256z'/%3E%3C/svg%3E") no-repeat;

/* Category */
@categoryBackground: @darkWhite;
Expand Down

0 comments on commit 22d2d0d

Please sign in to comment.