Skip to content

Commit 8e48ccd

Browse files
committed
Switch icons to img tags rather than inline svgs
1 parent 810022d commit 8e48ccd

File tree

8 files changed

+66
-77
lines changed

8 files changed

+66
-77
lines changed

src/labs/ia-combo-box/caret-closed-icon.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 8 additions & 0 deletions
Loading

src/labs/ia-combo-box/caret-open-icon.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 8 additions & 0 deletions
Loading

src/labs/ia-combo-box/clear-icon.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/labs/ia-combo-box/clear.svg

Lines changed: 9 additions & 0 deletions
Loading

src/labs/ia-combo-box/ia-combo-box.ts

Lines changed: 13 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -16,44 +16,17 @@ import { msg } from '@lit/localize';
1616

1717
import {
1818
hasAnyOf,
19+
isSubsequence,
1920
type IAComboBoxBehavior,
2021
type IAComboBoxFilterFunction,
2122
type IAComboBoxFilterOption,
2223
type IAComboBoxFilterPreset,
2324
type IAComboBoxOption,
2425
} from './models';
2526

26-
import caretClosedIcon from './caret-closed-icon';
27-
import caretOpenIcon from './caret-open-icon';
28-
import clearIcon from './clear-icon';
29-
30-
/**
31-
* Tests whether the given `haystack` string has the given `needle` as a subsequence.
32-
* Returns `true` if the characters of `needle` appear in order within `haystack`,
33-
* regardless of whether they are contiguous. Returns `false` otherwise.
34-
*
35-
* E.g., `ace` is a subsequence of `archive` (but not a contiguous substring).
36-
*
37-
* Note: The empty string is a subsequence of any string, including itself.
38-
*
39-
* @param needle The potential subsequence to check for inside `haystack`.
40-
* @param haystack The string to be tested for containing the `needle` subsequence.
41-
* @returns Whether `haystack` has `needle` as a subsequence.
42-
*/
43-
const isSubsequence = (needle: string, haystack: string): boolean => {
44-
const needleLen = needle.length;
45-
const haystackLen = haystack.length;
46-
if (needleLen === 0) return true;
47-
48-
let needleIdx = 0;
49-
let haystackIdx = 0;
50-
while (haystackIdx < haystackLen) {
51-
if (haystack[haystackIdx] === needle[needleIdx]) needleIdx += 1;
52-
if (needleIdx >= needleLen) return true;
53-
haystackIdx += 1;
54-
}
55-
return false;
56-
};
27+
import caretClosedIcon from './caret-closed.svg';
28+
import caretOpenIcon from './caret-open.svg';
29+
import clearIcon from './clear.svg';
5730

5831
/**
5932
* Map from filter preset keys to their associated filtering function.
@@ -434,10 +407,13 @@ export class IAComboBox extends LitElement {
434407
id="clear-button"
435408
class=${classMap({ visible: this.shouldShowClearButton })}
436409
part="clear-button"
410+
tabindex="-1"
437411
@click=${this.handleClearButtonClick}
438412
>
439413
<span class="sr-only">${msg('Clear')}</span>
440-
<slot name="clear-button" class="clear-icon">${clearIcon}</slot>
414+
<slot name="clear-button">
415+
<img class="icon" src=${clearIcon}>
416+
</slot>
441417
</button>
442418
`;
443419
}
@@ -448,11 +424,11 @@ export class IAComboBox extends LitElement {
448424
*/
449425
private get caretTemplate(): TemplateResult {
450426
return html`
451-
<slot name="caret-closed" class="caret-icon" ?hidden=${this.open}>
452-
${caretClosedIcon}
427+
<slot name="caret-closed" ?hidden=${this.open}>
428+
<img class="icon" src=${caretClosedIcon}>
453429
</slot>
454-
<slot name="caret-open" class="caret-icon" ?hidden=${!this.open}>
455-
${caretOpenIcon}
430+
<slot name="caret-open" ?hidden=${!this.open}>
431+
<img class="icon" src=${caretOpenIcon}>
456432
</slot>
457433
`;
458434
}
@@ -1211,8 +1187,7 @@ export class IAComboBox extends LitElement {
12111187
text-align: center;
12121188
}
12131189
1214-
.caret-icon > svg,
1215-
.clear-icon > svg {
1190+
.icon {
12161191
width: 14px;
12171192
height: 14px;
12181193
}

src/labs/ia-combo-box/models.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,31 @@ export type IAComboBoxFilterOption =
8181
export function hasAnyOf<T>(map: Map<T, unknown>, keys: T[]): boolean {
8282
return keys.some((prop) => map.has(prop));
8383
}
84+
85+
/**
86+
* Tests whether the given `haystack` string has the given `needle` as a subsequence.
87+
* Returns `true` if the characters of `needle` appear in order within `haystack`,
88+
* regardless of whether they are contiguous. Returns `false` otherwise.
89+
*
90+
* E.g., `ace` is a subsequence of `archive` (but not a contiguous substring).
91+
*
92+
* Note: The empty string is a subsequence of any string, including itself.
93+
*
94+
* @param needle The potential subsequence to check for inside `haystack`.
95+
* @param haystack The string to be tested for containing the `needle` subsequence.
96+
* @returns Whether `haystack` has `needle` as a subsequence.
97+
*/
98+
export function isSubsequence(needle: string, haystack: string): boolean {
99+
const needleLen = needle.length;
100+
const haystackLen = haystack.length;
101+
if (needleLen === 0) return true;
102+
103+
let needleIdx = 0;
104+
let haystackIdx = 0;
105+
while (haystackIdx < haystackLen) {
106+
if (haystack[haystackIdx] === needle[needleIdx]) needleIdx += 1;
107+
if (needleIdx >= needleLen) return true;
108+
haystackIdx += 1;
109+
}
110+
return false;
111+
}

0 commit comments

Comments
 (0)