Skip to content

Commit 22d2d0d

Browse files
authored
feat(search): support remove icon
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.
1 parent 16a9552 commit 22d2d0d

File tree

4 files changed

+58
-38
lines changed

4 files changed

+58
-38
lines changed

src/definitions/modules/search.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@
126126
.on('mousedown' + eventNamespace, selector.results, module.event.result.mousedown)
127127
.on('mouseup' + eventNamespace, selector.results, module.event.result.mouseup)
128128
.on('click' + eventNamespace, selector.result, module.event.result.click)
129+
.on('click' + eventNamespace, selector.remove, module.event.remove.click)
129130
;
130131
},
131132
},
@@ -201,6 +202,12 @@
201202
callback();
202203
}
203204
},
205+
remove: {
206+
click: function () {
207+
module.clear.value();
208+
$prompt.trigger('focus');
209+
},
210+
},
204211
result: {
205212
mousedown: function () {
206213
module.resultsClicked = true;
@@ -837,6 +844,9 @@
837844
$module.data(metadata.cache, cache);
838845
}
839846
},
847+
value: function () {
848+
module.set.value('');
849+
},
840850
},
841851

842852
read: {
@@ -1456,6 +1466,7 @@
14561466

14571467
selector: {
14581468
prompt: '.prompt',
1469+
remove: '> .icon.input > .remove.icon',
14591470
searchButton: '.search.button',
14601471
results: '.results',
14611472
message: '.results > .message',

src/definitions/modules/search.less

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -271,37 +271,46 @@
271271
Types
272272
*******************************/
273273

274-
& when (@variationSearchSelection) {
274+
& when (@variationSearchClear) {
275275
/* --------------
276-
Selection
276+
Clear Icon
277277
--------------- */
278278

279-
.ui.search.selection .prompt {
280-
border-radius: @selectionPromptBorderRadius;
279+
.ui.search > .icon.input > .remove.icon {
280+
pointer-events: all;
281+
transition: @clearableIconTransition;
282+
cursor: pointer;
283+
opacity: @clearableIconOpacity;
284+
&:hover {
285+
opacity: @clearableIconHoverOpacity;
286+
}
281287
}
282-
283-
/* Remove input */
284-
.ui.search.selection > .icon.input > .remove.icon {
285-
pointer-events: none;
286-
position: absolute;
287-
left: auto;
288-
opacity: 0;
289-
color: @selectionCloseIconColor;
290-
top: @selectionCloseTop;
291-
right: @selectionCloseRight;
292-
transition: @selectionCloseTransition;
288+
.ui.search > .icon.input:not([class*="left icon"]) > .icon ~ .remove.icon {
289+
right: @clearableIconInputRight;
293290
}
294-
.ui.search.selection > .icon.input > .active.remove.icon {
291+
.ui.search input[type="search"]::-webkit-search-cancel-button {
292+
-webkit-appearance: none;
295293
cursor: pointer;
296-
opacity: @selectionCloseIconOpacity;
297-
pointer-events: auto;
294+
transition: @clearableIconTransition;
295+
opacity: @clearableIconOpacity;
296+
background: @clearableIconBackground;
297+
height: @clearableIconHeight;
298+
width: @clearableIconWidth;
299+
&:hover {
300+
opacity: @clearableIconHoverOpacity;
301+
}
302+
}
303+
& when (@variationSearchLoading) {
304+
.ui.loading.search input[type="search"]::-webkit-search-cancel-button {
305+
display: none;
306+
}
298307
}
299-
.ui.search.selection > .icon.input:not([class*="left icon"]) > .icon ~ .remove.icon {
300-
right: @selectionCloseIconInputRight;
308+
.ui.search > .icon.input > input:placeholder-shown ~ .remove.icon,
309+
.ui.search.loading > .icon.input > .remove.icon {
310+
display: none;
301311
}
302-
.ui.search.selection > .icon.input > .remove.icon:hover {
303-
opacity: @selectionCloseIconHoverOpacity;
304-
color: @selectionCloseIconHoverColor;
312+
.ui.search > .icon.input > input:-ms-input-placeholder ~ .remove.icon when (@supportIE) {
313+
display: none;
305314
}
306315
}
307316

src/themes/default/globals/variation.variables

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@
681681

682682
/* Search */
683683
@variationSearchDisabled: true;
684-
@variationSearchSelection: true;
684+
@variationSearchClear: true;
685685
@variationSearchCategory: true;
686686
@variationSearchHorizontalCategory: true;
687687
@variationSearchLoading: true;

src/themes/default/modules/search.variables

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -126,20 +126,20 @@
126126
Types
127127
*******************************/
128128

129-
/* Selection */
130-
@selectionPromptBorderRadius: @defaultBorderRadius;
131-
132-
@selectionCloseTop: 0;
133-
@selectionCloseTransition:
134-
color @defaultDuration @defaultEasing,
135-
opacity @defaultDuration @defaultEasing;
136-
@selectionCloseRight: 0;
137-
@selectionCloseIconOpacity: 0.8;
138-
@selectionCloseIconColor: "";
139-
@selectionCloseIconHoverOpacity: 1;
140-
@selectionCloseIconHoverColor: @red;
141-
142-
@selectionCloseIconInputRight: 1.85714em;
129+
/* Clearable */
130+
@clearableIconTransition: opacity @defaultDuration @defaultEasing;
131+
@clearableIconOpacity: 0.6;
132+
@clearableIconHoverOpacity: 1;
133+
@clearableIconWidth: 1em;
134+
@clearableIconHeight: @clearableIconWidth;
135+
136+
@clearableIconInputRight: 1.85714em;
137+
138+
/*
139+
* Times icon taken from Font Awesome Free 5.15.4 by @fontawesome [https://fontawesome.com]
140+
* License - https://fontawesome.com/license/free
141+
*/
142+
@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;
143143

144144
/* Category */
145145
@categoryBackground: @darkWhite;

0 commit comments

Comments
 (0)