Skip to content

Commit fb9eb91

Browse files
authored
Merge pull request #51 from zazuko/clear-endpoint-btn
Add a clear button for the endpoint field
2 parents 50ea097 + f6cb66e commit fb9eb91

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

.changeset/gentle-parts-unite.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@zazuko/yasgui": minor
3+
---
4+
5+
This adds a clear button for the endpoint field.

packages/yasgui/src/endpointSelect.scss

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,26 @@
9797
display: none;
9898
}
9999
}
100+
101+
.clearEndpointBtn {
102+
border: 1px solid #d1d1d1;
103+
background-color: #d1d1d1;
104+
color: #505050;
105+
border-radius: 3px;
106+
cursor: pointer;
107+
108+
padding: 4px 8px;
109+
margin: 4px;
110+
111+
display: flex;
112+
align-items: center;
113+
justify-content: center;
114+
115+
opacity: 1;
116+
transition: opacity ease-in 200ms;
117+
118+
&:hover {
119+
opacity: 0.8;
120+
}
121+
}
100122
}

packages/yasgui/src/endpointSelect.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,20 @@ export class EndpointSelect extends EventEmitter {
8686
// Create field
8787
this.inputField = document.createElement("input");
8888
addClass(this.inputField, "autocomplete");
89-
// Clear the query string when clicking on the input field
90-
this.inputField.addEventListener("focusin", () => (this.inputField.value = ""));
89+
this.inputField.value = this.value;
9190
autocompleteWrapper.appendChild(this.inputField);
9291

92+
// Create clear button
93+
const clearBtn = document.createElement("button");
94+
clearBtn.title = "Clear endpoint";
95+
addClass(clearBtn, "clearEndpointBtn");
96+
clearBtn.innerText = "✖";
97+
clearBtn.addEventListener("click", () => {
98+
this.inputField.value = "";
99+
this.inputField.focus();
100+
});
101+
this.container.appendChild(clearBtn);
102+
93103
// Init autocomplete library
94104
new Autocomplete<CatalogueItem>({
95105
placeholder: "Search or add an endpoint",

0 commit comments

Comments
 (0)