Skip to content

Commit 7831eb2

Browse files
author
Steven Silvester
authored
Merge pull request jupyterlab#57 from ggbhat/search-clear-commandpallet
Added type search to command pallet search input
2 parents 90dd837 + 2b0aeb6 commit 7831eb2

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

Diff for: packages/default-theme/style/commandpalette.css

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@
2626
padding: 4px 6px;
2727
background: white;
2828
border: 1px solid #E0E0E0;
29+
position: relative;
2930
}
3031

3132

3233
/* <DEPRECATED> */ .p-CommandPalette-input, /* </DEPRECATED> */
3334
.lm-CommandPalette-input {
34-
width: 100%;
35+
width: 92%;
3536
border: none;
3637
outline: none;
3738
font-size: 16px;

Diff for: packages/widgets/src/commandpalette.ts

+19
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,14 @@ class CommandPalette extends Widget {
202202
*/
203203
refresh(): void {
204204
this._results = null;
205+
if(this.inputNode.value !== '') {
206+
let clear = this.node.getElementsByClassName('lm-close-icon')[0] as HTMLInputElement;
207+
clear.style.display = 'inherit'
208+
}
209+
else {
210+
let clear = this.node.getElementsByClassName('lm-close-icon')[0] as HTMLInputElement;
211+
clear.style.display = 'none'
212+
}
205213
this.update();
206214
}
207215

@@ -338,6 +346,13 @@ class CommandPalette extends Widget {
338346
return;
339347
}
340348

349+
// Clear input if the target is clear button
350+
if((event.target as HTMLElement).classList.contains("lm-close-icon")) {
351+
this.inputNode.value = '';
352+
this.refresh();
353+
return;
354+
}
355+
341356
// Find the index of the item which was clicked.
342357
let index = ArrayExt.findFirstIndex(this.contentNode.children, node => {
343358
return node.contains(event.target as HTMLElement);
@@ -1024,9 +1039,12 @@ namespace Private {
10241039
let wrapper = document.createElement('div');
10251040
let input = document.createElement('input');
10261041
let content = document.createElement('ul');
1042+
let clear = document.createElement('button');
10271043
search.className = 'lm-CommandPalette-search';
10281044
wrapper.className = 'lm-CommandPalette-wrapper';
10291045
input.className = 'lm-CommandPalette-input';
1046+
clear.className = 'lm-close-icon';
1047+
10301048
content.className = 'lm-CommandPalette-content';
10311049
/* <DEPRECATED> */
10321050
search.classList.add('p-CommandPalette-search');
@@ -1036,6 +1054,7 @@ namespace Private {
10361054
/* </DEPRECATED> */
10371055
input.spellcheck = false;
10381056
wrapper.appendChild(input);
1057+
wrapper.appendChild(clear);
10391058
search.appendChild(wrapper);
10401059
node.appendChild(search);
10411060
node.appendChild(content);

Diff for: packages/widgets/style/commandpalette.css

+27
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,30 @@
7676
white-space: nowrap;
7777
text-overflow: ellipsis;
7878
}
79+
80+
.lm-close-icon {
81+
border:1px solid transparent;
82+
background-color: transparent;
83+
position: absolute;
84+
z-index:1;
85+
right:3%;
86+
top: 0;
87+
bottom: 0;
88+
margin: auto;
89+
padding: 7px 0;
90+
display: none;
91+
vertical-align: middle;
92+
outline: 0;
93+
cursor: pointer;
94+
}
95+
.lm-close-icon:after {
96+
content: "X";
97+
display: block;
98+
width: 15px;
99+
height: 15px;
100+
text-align: center;
101+
color:#000;
102+
font-weight: normal;
103+
font-size: 12px;
104+
cursor: pointer;
105+
}

0 commit comments

Comments
 (0)