Skip to content

Commit dac2e45

Browse files
committed
chore: updated arrow-down functionality
1 parent 8d27b71 commit dac2e45

File tree

4 files changed

+179
-132
lines changed

4 files changed

+179
-132
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<form class="container">
2+
<div class="search-input-container">
3+
<pf-search-input disabled id="search-input" name="search" placeholder="Search">
4+
<pf-option>Blue</pf-option>
5+
<pf-option>Green</pf-option>
6+
<pf-option>Magenta</pf-option>
7+
<pf-option>Orange</pf-option>
8+
<pf-option>Purple</pf-option>
9+
<pf-option>Periwinkle</pf-option>
10+
<pf-option>Pink</pf-option>
11+
<pf-option>Red</pf-option>
12+
<pf-option>Yellow</pf-option>
13+
</pf-search-input>
14+
<pf-button> Search</pf-button>
15+
</div>
16+
</form>
17+
18+
<script type="module">
19+
import '@patternfly/elements/pf-search-input/pf-search-input.js';
20+
</script>
21+
22+
<style>
23+
.container {
24+
padding: 40px;
25+
.search-input-container {
26+
display: flex;
27+
align-items: center;
28+
justify-content: flex-start;
29+
#search-input {
30+
margin-right: 1rem;
31+
}
32+
}
33+
}
34+
</style>

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

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@
6868
--pf-c-search-input__toggle-clear--toggle-button--PaddingLeft: var(--pf-global--spacer--sm, 0.5rem);
6969
--pf-c-search-input__toggle-button--Color: var(--pf-global--Color--100, #151515);
7070
--pf-c-search-input__list-item--m-loading--PaddingTop: var(--pf-global--spacer--sm, 0.5rem);
71+
72+
/* --pf-c-search-input__toggle--FontSize: var(--pf-global--FontSize--md, 1rem);
73+
--pf-c-search-input__toggle--FontWeight: var(--pf-global--FontWeight--normal, 400);
74+
--pf-c-search-input__toggle--LineHeight: var(--pf-global--LineHeight--md, 1.5);
75+
--pf-c-search-input__toggle--BackgroundColor: var(--pf-global--BackgroundColor--100, #fff); */
7176
}
7277

7378
:host,
@@ -83,8 +88,9 @@
8388
display: none !important;
8489
}
8590

86-
:host([disabled]) {
91+
:host([aria-disabled="true"]) {
8792
pointer-events: none !important;
93+
cursor: not-allowed !important;
8894
}
8995

9096
#outer.disabled {
@@ -107,6 +113,8 @@
107113
#outer.expanded #listbox-container {
108114
opacity: 1;
109115
z-index: 9999 !important;
116+
max-height: 300px;
117+
overflow: hidden;
110118
}
111119

112120
#listbox {
@@ -122,22 +130,22 @@
122130
border-color: var(--pf-theme--color--surface--lighter, #f0f0f0) !important;
123131
pointer-events: none;
124132
cursor: not-allowed;
125-
;
133+
126134
--_active-descendant-color: transparent;
127135
--_svg-color: var(--pf-c-list__item-icon--Color, #6a6e73) !important;
128136
}
129137

130138
#toggle {
131-
background-color: var(--pf-theme--color--surface--lightest, #fff) !important;
139+
background-color: var(--pf-c-search-input__toggle--BackgroundColor, #fff) !important;
132140
}
133141

134142
#toggle,
135143
#toggle-input {
136144
display: flex;
137145
font-family: var(--pf-global--FontFamily--sans-serif, "RedHatTextUpdated", "Overpass", overpass, helvetica, arial, sans-serif);
138-
font-size: var(--pf-global--FontSize--md, 16px);
139-
font-weight: var(--pf-global--FontWeight--normal, 400);
140-
line-height: 1.6;
146+
font-size: var(--pf-c-search-input__toggle--FontSize, 1rem);
147+
font-weight: var( --pf-c-search-input__toggle--FontWeight, 400);
148+
line-height: var(--pf-c-search-input__toggle--LineHeight, 1.5);
141149
}
142150

143151
#toggle {
@@ -160,7 +168,6 @@
160168
text-align: left;
161169
border-radius: 0;
162170
padding-left: 3rem;
163-
/*Change it to variable*/
164171
}
165172

166173
#toggle-input {
@@ -172,6 +179,7 @@
172179

173180
.disabled #toggle-input {
174181
pointer-events: none;
182+
cursor: not-allowed;
175183
}
176184

177185
#close-button {

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

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ export class PfSearchInput extends LitElement {
174174
requestHideListbox: () => void (this.expanded &&= false),
175175
setItemHidden: (item, hidden) => (item.id !== 'placeholder') && void (item.hidden = hidden),
176176
isItem: item => item instanceof PfOption,
177-
setItemActive: (item, active) => item.active = active,
178-
setItemSelected: (item, selected) => item.selected = selected,
177+
setItemActive: (item, active) => this.#setItemActive(item, active),
178+
setItemSelected: (item, selected) => this.#setItemSelected(item, selected),
179179
});
180180

181181
static {
@@ -252,9 +252,10 @@ export class PfSearchInput extends LitElement {
252252
</div>
253253
<input
254254
id="toggle-input"
255-
?disabled="${disabled}"
256255
@input=${this.#onChange}
257256
@keyup=${this.#onSubmit}
257+
@keydown=${this.#onKeyDown}
258+
aria-disabled="${disabled}"
258259
placeholder="${placeholder}"
259260
>
260261
<div class="close-button-container">
@@ -316,13 +317,6 @@ export class PfSearchInput extends LitElement {
316317
this.dispatchEvent(new PfSearchChangeEvent());
317318
}
318319

319-
@observes('value')
320-
private collapseOnEmpty() {
321-
if (this.value === '') {
322-
this.expanded = false;
323-
}
324-
}
325-
326320
async #doExpand() {
327321
try {
328322
await this.#float.show({ placement: this.position || 'bottom', flip: !!this.enableFlip });
@@ -396,16 +390,41 @@ export class PfSearchInput extends LitElement {
396390
}
397391
}
398392

393+
#onKeyDown(event: KeyboardEvent) {
394+
const target = event.target as HTMLElement;
395+
if (target?.getAttribute('aria-disabled') === 'true') {
396+
// Allow Tab and Shift+Tab to move focus
397+
if (event.key === 'Tab') {
398+
return;
399+
}
400+
event.preventDefault();
401+
event.stopImmediatePropagation();
402+
}
403+
}
404+
399405
#delay(ms: number): Promise<void> {
400406
return new Promise(resolve => setTimeout(resolve, ms));
401407
}
402408

403409
async #showListbox() {
404410
await this.#delay(10);
405-
if (this.value !== '') {
411+
if (!this.disabled) {
406412
this.expanded ||= true;
407413
}
408414
}
415+
416+
#setItemSelected(item: PfOption, selected: boolean) {
417+
item.selected = selected;
418+
this.#setItemActive(item, selected);
419+
}
420+
421+
#setItemActive(item: PfOption, active: boolean) {
422+
item.active = active;
423+
if (this.expanded) {
424+
const activeOption = this.querySelector('pf-option[active]');
425+
activeOption?.scrollIntoView({ behavior: 'auto', block: 'nearest', inline: 'nearest' });
426+
}
427+
}
409428
}
410429

411430
declare global {

0 commit comments

Comments
 (0)