Skip to content

Commit 1060922

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

File tree

4 files changed

+46
-53
lines changed

4 files changed

+46
-53
lines changed

‎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
varli=helper.node("li|class:auto-suggest-list-item");
180-
varanchor=helper.node("a|href:#,tabindex:1,class:auto-suggest-link");
180+
varbutton=helper.node("button|tabindex:1,class:auto-suggest-item");
181181
varicon=helper.node("span|class:auto-suggest-icon fa-"+arrayItem.name);
182182
if(arrayItem.styles.includes("solid")){
183183
helper.addClass(icon,"fas");
184184
}elseif(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
vartext=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-
varautoSuggestWrapper=helper.e(".auto-suggest-wrapper");
200+
var_renderAutoSuggest=function(){
201+
varautoSuggestInput=helper.e(".auto-suggest-input");
202+
varautoSuggest=helper.e(".auto-suggest");
202203
varautoSuggestList=helper.e(".auto-suggest-list");
203-
if(autoSuggestList){
204+
if(autoSuggest){
204205
while(autoSuggestList.lastChild){
205206
autoSuggestList.removeChild(autoSuggestList.lastChild);
206207
};
207208
}else{
208-
varstyle={
209-
left: autoSuggestWrapper.getBoundingClientRect().left,
210-
top: autoSuggestWrapper.getBoundingClientRect().bottom+window.scrollY,
211-
width: autoSuggestWrapper.getBoundingClientRect().width
209+
varbox={
210+
left: autoSuggestInput.getBoundingClientRect().left,
211+
top: autoSuggestInput.getBoundingClientRect().bottom+window.scrollY,
212+
width: autoSuggestInput.getBoundingClientRect().width
212213
};
214+
varautoSuggest=helper.node("div|class:auto-suggest list-unstyled");
213215
varautoSuggestList=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-
varautoSuggestList=helper.e(".auto-suggest-list");
231-
if(autoSuggestList){
232-
autoSuggestList.remove();
233+
varautoSuggest=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
vardisplayIconLableIcon=helper.node("span|class:label-icon");
699699
vardisplayIconFormIndent=helper.node("div|class:form-indent");
700700
vardisplayIconInputWrap=helper.node("div|class:input-wrap");
701-
vardisplayIconFormGroup=helper.node("div|class:form-group form-group-block mb-0 auto-suggest-wrapper");
701+
vardisplayIconFormGroup=helper.node("div|class:form-group form-group-block mb-0 auto-suggest-input");
702702
vardisplayIconInput=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
vardisplayIconFormGroupText=helper.node("div|class:form-group-text link-form-text-icon disabled,tabindex:-1");
704704
vardisplayIconFormGroupClear=helper.node("button|class:link-form-icon-clear button mb-0,type:button,tabindex:1,disabled");

0 commit comments

Comments
(0)