Skip to content

Commit 03d0269

Browse files
committed
chore: search input updated
1 parent 17b1361 commit 03d0269

File tree

2 files changed

+68
-20
lines changed

2 files changed

+68
-20
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<pf-search-input></pf-search-input>
2+
3+
<script type="module">
4+
import '@patternfly/elements/pf-search-input/pf-search-input.js';
5+
</script>
6+
7+
<style>
8+
pf-search-input {
9+
/* insert demo styles */
10+
}
11+
</style>
12+

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

Lines changed: 56 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import {
99
type Placement,
1010
} from '@patternfly/pfe-core/controllers/floating-dom-controller.js';
1111
import '@patternfly/elements/pf-text-input/pf-text-input.js';
12-
12+
import { arraysAreEquivalent } from '@patternfly/pfe-core/functions/arraysAreEquivalent.js';
13+
import '@patternfly/elements/pf-icon/pf-icon.js';
1314
import styles from './pf-search-input.css';
1415

1516
/**
@@ -34,16 +35,16 @@ export class PfSearchInput extends LitElement {
3435
#float = new FloatingDOMController(this, { content: () => this._listboxContainer });
3536

3637

37-
static template: TemplateResult<1> = html`
38-
<pf-text-input-autocomplete></pf-text-input-autocomplete>`;
38+
// static template: TemplateResult<1> = html`
39+
// <pf-text-input-autocomplete></pf-text-input-autocomplete>`;
3940

40-
controller: ComboboxController<HTMLOptionElement> = ComboboxController.of(this, {
41+
#combobox: ComboboxController<HTMLOptionElement> = ComboboxController.of(this, {
4142
multi: false,
4243
getItems: () => this.options,
4344
isItem: item => item instanceof HTMLOptionElement,
4445
getFallbackLabel: () => 'options',
4546
getListboxElement: () => this.listbox ?? null,
46-
getToggleButton: () => this.button ?? null,
47+
getToggleButton: () => this.combobox ?? null,
4748
getComboboxInput: () => this.combobox ?? null,
4849
isExpanded: () => this.expanded,
4950
requestShowListbox: () => void (this.expanded ||= true),
@@ -52,6 +53,15 @@ export class PfSearchInput extends LitElement {
5253
setItemSelected: (item, selected) => item.selected = selected,
5354
});
5455

56+
/**
57+
* Single select option value for single select menus,
58+
* or array of select option values for multi select.
59+
*/
60+
@property({ hasChanged: (a, b) => !arraysAreEquivalent(a, b) })
61+
set selected(selected: any) {
62+
const list = Array.isArray(selected) ? selected : [selected];
63+
this.#combobox.selected = list;
64+
}
5565

5666
/** List of options */
5767
get options(): HTMLOptionElement[] {
@@ -72,23 +82,49 @@ export class PfSearchInput extends LitElement {
7282
return this.options.find(x => x.classList.contains('active'));
7383
}
7484

75-
85+
//<input id="combobox">
7686
render(): TemplateResult<1> {
7787
return html`
78-
<input id="combobox">
79-
<button id="button">Show Options</button>
80-
<div id="listbox" ?hidden="${!this.expanded}">
81-
<option id="placeholder" aria-disabled="true">Select an Option</option>
82-
<option>1</option>
83-
<option>2</option>
84-
<option>31</option>
85-
<option>41</option>
86-
<option>52</option>
87-
<option>63</option>
88-
<option>74</option>
89-
<option>8</option>
90-
<option>9</option>
91-
<option>10</option>
88+
<pf-text-input id="combobox" type="text" placeholder="Placeholder"></pf-text-input>
89+
<pf-button disabled plain label="Close">
90+
<svg fill="currentColor" height="1em" width="1em" viewBox="0 0 352 512">
91+
<path d="M242.72 256l100.07-100.07c12.28-12.28 12.28-32.19
92+
0-44.48l-22.24-22.24c-12.28-12.28-32.19-12.28-44.48 0L176
93+
189.28 75.93 89.21c-12.28-12.28-32.19-12.28-44.48
94+
0L9.21 111.45c-12.28 12.28-12.28 32.19 0 44.48L109.28 256 9.21
95+
356.07c-12.28 12.28-12.28 32.19 0 44.48l22.24 22.24c12.28
96+
12.28 32.2 12.28 44.48 0L176 322.72l100.07 100.07c12.28 12.28 32.2 12.28
97+
44.48 0l22.24-22.24c12.28-12.28 12.28-32.19 0-44.48L242.72 256z">
98+
</path>
99+
</svg>
100+
</pf-button>
101+
<pf-button disabled plain label="Search">
102+
<svg fill="currentColor" height="1em" width="1em" viewBox="0 0 512 512">
103+
<path d="M256.233,5.756c-71.07,15.793-141.44,
104+
87.863-155.834,159.233c-11.495,57.076,0.3,111.153,
105+
27.688,154.335L6.339,441.172c-8.596,8.596-8.596,
106+
22.391,0,30.987l33.286,33.286c8.596,8.596,22.391,
107+
8.596,30.987,0L192.26,383.796c43.282,
108+
27.688,97.559,39.683,154.734,28.188c79.167-15.893,142.04-77.067,
109+
159.632-155.934C540.212,104.314,407.968-27.93,256.233,
110+
5.756z M435.857,208.37c0,72.869-59.075,131.944-131.944,131.944
111+
S171.969,281.239,171.969,208.37S231.043,76.426,303.913,
112+
76.426S435.857,135.501,435.857,208.37z">
113+
</path>
114+
</svg>
115+
</pf-button>
116+
<div id="listbox-container">
117+
<div id="listbox" ?hidden="${!this.expanded}">
118+
<option id="placeholder" aria-disabled="true">Select an Option</option>
119+
<optgroup label="Swedish Cars">
120+
<option value="volvo">Volvo</option>
121+
<option value="saab">Saab</option>
122+
</optgroup>
123+
<optgroup label="German Cars">
124+
<option value="mercedes">Mercedes</option>
125+
<option value="audi">Audi</option>
126+
</optgroup>
127+
</div>
92128
</div>
93129
`;
94130
}

0 commit comments

Comments
 (0)