Skip to content

Commit a332552

Browse files
committed
chore: close button functionality implemented
1 parent 34900a4 commit a332552

File tree

2 files changed

+43
-23
lines changed

2 files changed

+43
-23
lines changed

elements/pf-search-input/pf-search-input.css

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@
224224
}
225225

226226
#toggle,
227-
#toggle-button,
227+
/* #toggle-button, */
228228
#toggle-input {
229229
display: flex;
230230
align-items: center;
@@ -251,8 +251,9 @@
251251
border-color: var(--pf-theme--color--surface--lighter, #f0f0f0) !important;
252252
}
253253

254-
#toggle-input,
255-
#toggle-button {
254+
255+
/* #toggle-button, */
256+
#toggle-input {
256257
background: transparent;
257258
border: none;
258259
text-align: left;
@@ -273,7 +274,7 @@
273274
pointer-events: none;
274275
}
275276

276-
#toggle-button {
277+
#close-button {
277278
color: currentColor;
278279
background-color: transparent;
279280
justify-content: flex-end;
@@ -294,9 +295,9 @@
294295
border-bottom-width: var(--pf-c-select__toggle--focus--before--BorderBottomWidth);
295296
}
296297

297-
#outer.typeahead #toggle-button {
298+
/* #outer.typeahead #toggle-button {
298299
flex: 0 0 auto;
299-
}
300+
} */
300301

301302
#toggle-badge {
302303
flex: 1 0 auto;

elements/pf-search-input/pf-search-input.ts

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,11 @@ export class PfSearchInput extends LitElement {
148148
const hideLightDomItems = !ComboboxController.supportsCrossRootActiveDescendant;
149149

150150
return html`
151-
<div id="outer"
152-
style="${styleMap(styles)}"
153-
class="${classMap({ disabled, expanded, [anchor]: !!anchor, [alignment]: !!alignment })}">
151+
<div
152+
id="outer"
153+
style="${styleMap(styles)}"
154+
class="${classMap({ disabled, expanded, [anchor]: !!anchor, [alignment]: !!alignment })}"
155+
>
154156
<div id="toggle">
155157
<div class="search-icon">
156158
<svg fill="currentColor" height="1em" width="1em" viewBox="0 0 512 512">
@@ -167,11 +169,19 @@ export class PfSearchInput extends LitElement {
167169
</path>
168170
</svg>
169171
</div>
170-
<input id="toggle-input"
171-
?disabled="${disabled}"
172-
placeholder="${placeholder || this.#buttonLabel}">
173-
174-
<pf-button id="toggle-button" plain label="Close">
172+
<input
173+
id="toggle-input"
174+
?disabled="${disabled}"
175+
placeholder="${placeholder || this.#buttonLabel}"
176+
>
177+
<button style="width: 0px; height: 0px; padding: 0px; visibility: hidden;" id="toggle-button"></button>
178+
<pf-button
179+
@click="${this.#OnClose}"
180+
?hidden="${(!expanded && this._toggleInput?.value.trim() === "")}"
181+
id="close-button"
182+
plain
183+
label="Close"
184+
>
175185
<svg fill="currentColor" height="1em" width="1em" viewBox="0 0 352 512">
176186
<path d="M242.72 256l100.07-100.07c12.28-12.28 12.28-32.19
177187
0-44.48l-22.24-22.24c-12.28-12.28-32.19-12.28-44.48 0L176
@@ -181,17 +191,18 @@ export class PfSearchInput extends LitElement {
181191
12.28 32.2 12.28 44.48 0L176 322.72l100.07 100.07c12.28 12.28 32.2 12.28
182192
44.48 0l22.24-22.24c12.28-12.28 12.28-32.19 0-44.48L242.72 256z">
183193
</path>
184-
</svg>
185-
</pf-button>
194+
</svg>
195+
</pf-button>
186196
</div>
187-
<div id="listbox-container"
188-
?hidden="${!expanded}"
189-
style="${styleMap({
190-
marginTop: `${height || 0}px`,
191-
width: width ? `${width}px` : 'auto',
192-
})}">
197+
<div
198+
id="listbox-container"
199+
?hidden="${!expanded}"
200+
style="${styleMap({
201+
marginTop: `${height || 0}px`,
202+
width: width ? `${width}px` : 'auto',
203+
})}"
204+
>
193205
<div id="listbox">
194-
195206
${this.#combobox.renderItemsToShadowRoot()}
196207
<slot ?hidden="${hideLightDomItems}"></slot>
197208
</div>
@@ -288,6 +299,14 @@ export class PfSearchInput extends LitElement {
288299
await this.show();
289300
}
290301
}
302+
303+
async #OnClose(){
304+
if (this.expanded) {
305+
await this.hide();
306+
}
307+
this.value = "";
308+
this._toggleInput!.value = this.value;
309+
}
291310
}
292311

293312
declare global {

0 commit comments

Comments
 (0)