Skip to content

Commit 1060922

Browse files
committed
[refactor] improve auto suggest list structure
1 parent f3ad49a commit 1060922

4 files changed

Lines changed: 46 additions & 53 deletions

File tree

src/css/auto-suggest.css

Lines changed: 23 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
font-size: 1em;
55
}
66

7-
.auto-suggest-list {
7+
.auto-suggest {
88
background-color: rgb(var(--theme-gray-02));
99
margin-top: 0.5em;
1010
padding: 1em;
@@ -15,67 +15,57 @@
1515
max-height: 40vh;
1616
border-radius: var(--theme-radius);
1717
overflow-y: auto;
18-
z-index: var(--z-index-auto-suggest-list);
19-
display: flex;
20-
flex-direction: row;
21-
flex-wrap: wrap;
18+
z-index: var(--z-index-auto-suggest);
2219
box-shadow: var(--layout-shadow-large);
2320
}
2421

25-
.auto-suggest-list-item {
26-
flex-basis: 33.3333333333%;
27-
}
28-
29-
.auto-suggest-list-item:not(:last-child) {
30-
margin-bottom: 0;
22+
.auto-suggest-list {
23+
display: grid;
24+
grid-template-columns: repeat(3, 1fr);
3125
}
3226

33-
.auto-suggest-link {
27+
.auto-suggest-item {
28+
background-color: transparent;
3429
padding: 0.5em;
30+
margin: 0;
3531
border: 0;
3632
border-radius: var(--theme-radius);
3733
width: 100%;
3834
height: 100%;
35+
min-height: 6em;
3936
display: flex;
37+
position: relative;
38+
white-space: inherit;
4039
flex-direction: column;
41-
justify-content: flex-start;
40+
justify-content: center;
4241
align-items: center;
4342
transition: background-color var(--layout-timing-extra-fast), color var(--layout-timing-extra-fast), border-color var(--layout-timing-extra-fast), box-shadow var(--layout-timing-extra-fast);
4443
}
4544

46-
.auto-suggest-link:link,
47-
.auto-suggest-link:visited {
48-
color: rgb(var(--theme-gray-16));
49-
text-decoration: none;
45+
.auto-suggest-item:after {
46+
content: none;
5047
}
5148

52-
.auto-suggest-link:hover {
53-
background-color: rgb(var(--theme-gray-03));
54-
color: rgb(var(--form-input-text-hover));
55-
outline: none;
56-
text-decoration: none;
57-
box-shadow: var(--form-ring-hover);
49+
.auto-suggest-item:link,
50+
.auto-suggest-item:visited {
51+
background-color: transparent;
5852
}
5953

60-
.auto-suggest-link:focus {
61-
background-color: rgb(var(--theme-gray-01));
62-
color: rgb(var(--form-input-text-focus-active));
63-
outline: none;
64-
text-decoration: none;
65-
box-shadow: var(--form-ring-accent);
54+
.auto-suggest-item:hover {
55+
box-shadow: var(--form-ring-hover);
6656
}
6757

68-
.auto-suggest-link:active {
69-
color: rgb(var(--theme-style-text));
58+
.auto-suggest-item:focus {
59+
box-shadow: var(--form-ring-accent);
7060
}
7161

7262
.auto-suggest-icon {
7363
font-size: 2em;
7464
}
7565

7666
.auto-suggest-icon-text {
77-
color: rgb(var(--theme-gray-08));
78-
margin-top: 0.5em;
67+
margin-top: 1em;
7968
font-size: 0.6em;
8069
text-align: center;
70+
line-height: 1.6;
8171
}

src/css/variables.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@
191191
--z-index-shade: 5000;
192192
--z-index-modal: 6000;
193193
--z-index-menu: 7000;
194-
--z-index-auto-suggest-list: 8000;
194+
--z-index-auto-suggest: 8000;
195195
--z-index-dropdown: 9000;
196196
--z-index-edge: 10000;
197197
/* breakpoint */

src/js/auto-suggest.js

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -177,59 +177,62 @@ var autoSuggest = (function() {
177177
fontawesomeIcon: function() {
178178
suggestItems.forEach(function(arrayItem) {
179179
var li = helper.node("li|class:auto-suggest-list-item");
180-
var anchor = helper.node("a|href:#,tabindex:1,class:auto-suggest-link");
180+
var button = helper.node("button|tabindex:1,class:auto-suggest-item");
181181
var icon = helper.node("span|class:auto-suggest-icon fa-" + arrayItem.name);
182182
if (arrayItem.styles.includes("solid")) {
183183
helper.addClass(icon, "fas");
184184
} else if (arrayItem.styles.includes("brands")) {
185185
helper.addClass(icon, "fab");
186186
};
187-
anchor.addEventListener("click", function() {
187+
button.addEventListener("click", function() {
188188
link.render.autoSuggestIconAction(arrayItem);
189189
}, false);
190190
var text = helper.node("span:" + arrayItem.label + "|class:auto-suggest-icon-text");
191-
anchor.appendChild(icon);
192-
anchor.appendChild(text);
193-
li.appendChild(anchor);
191+
button.appendChild(icon);
192+
button.appendChild(text);
193+
li.appendChild(button);
194194
list.appendChild(li);
195195
});
196196
}
197197
};
198198
action[_currentInputOptions.type]();
199199
};
200-
var _renderAutoSuggestList = function() {
201-
var autoSuggestWrapper = helper.e(".auto-suggest-wrapper");
200+
var _renderAutoSuggest = function() {
201+
var autoSuggestInput = helper.e(".auto-suggest-input");
202+
var autoSuggest = helper.e(".auto-suggest");
202203
var autoSuggestList = helper.e(".auto-suggest-list");
203-
if (autoSuggestList) {
204+
if (autoSuggest) {
204205
while (autoSuggestList.lastChild) {
205206
autoSuggestList.removeChild(autoSuggestList.lastChild);
206207
};
207208
} else {
208-
var style = {
209-
left: autoSuggestWrapper.getBoundingClientRect().left,
210-
top: autoSuggestWrapper.getBoundingClientRect().bottom + window.scrollY,
211-
width: autoSuggestWrapper.getBoundingClientRect().width
209+
var box = {
210+
left: autoSuggestInput.getBoundingClientRect().left,
211+
top: autoSuggestInput.getBoundingClientRect().bottom + window.scrollY,
212+
width: autoSuggestInput.getBoundingClientRect().width
212213
};
214+
var autoSuggest = helper.node("div|class:auto-suggest list-unstyled");
213215
var autoSuggestList = helper.node("ul|class:auto-suggest-list list-unstyled");
214-
body.appendChild(autoSuggestList);
215-
autoSuggestList.setAttribute("style", "width: " + style.width + "px; top: " + style.top + "px; left: " + style.left + "px;");
216+
autoSuggest.appendChild(autoSuggestList);
217+
body.appendChild(autoSuggest);
218+
autoSuggest.setAttribute("style", "width: " + box.width + "px; top: " + box.top + "px; left: " + box.left + "px;");
216219
documentEvent.add();
217220
};
218221
_populateList(autoSuggestList);
219222
};
220223
if (suggestItems.length > 0) {
221224
_autoSuggestActive = true;
222-
_renderAutoSuggestList();
225+
_renderAutoSuggest();
223226
} else {
224227
render.close();
225228
};
226229
};
227230

228231
render.close = function() {
229232
mod.close();
230-
var autoSuggestList = helper.e(".auto-suggest-list");
231-
if (autoSuggestList) {
232-
autoSuggestList.remove();
233+
var autoSuggest = helper.e(".auto-suggest");
234+
if (autoSuggest) {
235+
autoSuggest.remove();
233236
documentEvent.remove();
234237
_currentInputOptions = {};
235238
_autoSuggestActive = false;

src/js/link.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ var link = (function() {
698698
var displayIconLableIcon = helper.node("span|class:label-icon");
699699
var displayIconFormIndent = helper.node("div|class:form-indent");
700700
var displayIconInputWrap = helper.node("div|class:input-wrap");
701-
var displayIconFormGroup = helper.node("div|class:form-group form-group-block mb-0 auto-suggest-wrapper");
701+
var displayIconFormGroup = helper.node("div|class:form-group form-group-block mb-0 auto-suggest-input");
702702
var displayIconInput = helper.node("input|type:text,class:form-group-item-grow link-form-input-icon auto-suggest-input,id:link-form-input-icon,placeholder:Search for Brands or Icons,tabindex:1,autocomplete:off,autocorrect:off,autocapitalize:off,spellcheck:false,disabled");
703703
var displayIconFormGroupText = helper.node("div|class:form-group-text link-form-text-icon disabled,tabindex:-1");
704704
var displayIconFormGroupClear = helper.node("button|class:link-form-icon-clear button mb-0,type:button,tabindex:1,disabled");

0 commit comments

Comments
 (0)