Skip to content

Commit b865d73

Browse files
authored
Merge pull request #288 from silinternational/add-clear-button
add(SearchableSelect): add clear button to SearchableSelect
2 parents 8dad471 + 3fd0539 commit b865d73

File tree

3 files changed

+36
-11
lines changed

3 files changed

+36
-11
lines changed

CHANGELOG.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
11
# Changelog
2+
23
All notable changes to this project will be documented in this file.
34
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html), enforced with [semantic-release](https://github.com/semantic-release/semantic-release).
45

56
## [11.5.0](https://github.com/silinternational/ui-components/compare/v11.4.2...v11.5.0) (2024-09-09)
67

7-
88
### Added
99

10-
* **DateInput:** add data-1p-ignore to prevent 1Password trying to fill ([c296811](https://github.com/silinternational/ui-components/commit/c29681127222afabceff914350aafebe38687dfc))
11-
* **MoneyInput:** add data-1p-ignore to prevent 1Password trying to fill ([6367aa8](https://github.com/silinternational/ui-components/commit/6367aa8f43c5544556039feaf848fff60002cf33))
12-
* **SearchableSelect:** add data-1p-ignore to SearchableSelect ([ce4bf4b](https://github.com/silinternational/ui-components/commit/ce4bf4be28a7c3ef5efe0636c47d4437e8fe71f0))
13-
* **Select:** add data-1p-ignore to prevent 1Password trying to fill ([1e502e2](https://github.com/silinternational/ui-components/commit/1e502e226144bf0c8b41a7535f8499d62df537e7))
10+
- **DateInput:** add data-1p-ignore to prevent 1Password trying to fill ([c296811](https://github.com/silinternational/ui-components/commit/c29681127222afabceff914350aafebe38687dfc))
11+
- **MoneyInput:** add data-1p-ignore to prevent 1Password trying to fill ([6367aa8](https://github.com/silinternational/ui-components/commit/6367aa8f43c5544556039feaf848fff60002cf33))
12+
- **SearchableSelect:** add data-1p-ignore to SearchableSelect ([ce4bf4b](https://github.com/silinternational/ui-components/commit/ce4bf4be28a7c3ef5efe0636c47d4437e8fe71f0))
13+
- **Select:** add data-1p-ignore to prevent 1Password trying to fill ([1e502e2](https://github.com/silinternational/ui-components/commit/1e502e226144bf0c8b41a7535f8499d62df537e7))
1414

1515
### [11.4.2](https://github.com/silinternational/ui-components/compare/v11.4.1...v11.4.2) (2024-09-06)
1616

17-
1817
### Fixed
1918

20-
* **Drawer:** fix A11y warning in Drawer ([275d2b9](https://github.com/silinternational/ui-components/commit/275d2b9f0944e82da7b275f043afc11b6e9296c1))
19+
- **Drawer:** fix A11y warning in Drawer ([275d2b9](https://github.com/silinternational/ui-components/commit/275d2b9f0944e82da7b275f043afc11b6e9296c1))
2120

2221
### [11.4.1](https://github.com/silinternational/ui-components/compare/v11.4.0...v11.4.1) (2024-07-09)
2322

components/custom/SearchableSelect/SearchableSelect.svelte

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export let showError = false
2323
2424
let element = {}
2525
let randomId = generateRandomID('dataList-')
26+
let savedChoice = ''
2627
2728
const dispatch = createEventDispatcher()
2829
@@ -32,6 +33,18 @@ const onChange = (e) => {
3233
choice = internalChoice
3334
element.blur()
3435
}
36+
37+
const clearChoice = () => {
38+
savedChoice = choice
39+
choice = ''
40+
}
41+
42+
const onBlur = () => {
43+
if (savedChoice && !choice) {
44+
choice = savedChoice
45+
}
46+
dispatch('check', choice)
47+
}
3548
</script>
3649

3750
<style>
@@ -80,6 +93,16 @@ const onChange = (e) => {
8093
border-color: var(--mdc-theme-status-error, var(--mdc-theme-error));
8194
color: var(--mdc-theme-status-error, var(--mdc-theme-error));
8295
}
96+
97+
.clear-button {
98+
cursor: pointer;
99+
padding: 5px;
100+
position: relative;
101+
right: 50px;
102+
border-radius: 4px;
103+
border: none;
104+
background-color: transparent;
105+
}
83106
</style>
84107

85108
<label class="custom-field" style="--field-padding: {padding}; {$$props.class || ''}">
@@ -98,11 +121,14 @@ const onChange = (e) => {
98121
value={choice}
99122
on:change={onChange}
100123
on:change
101-
on:blur={(e) => dispatch('check', e.target.value)}
124+
on:blur={onBlur}
102125
on:blur
103126
on:focus
104127
/>
105128
<span class="placeholder">{placeholder}</span>
129+
{#if choice}
130+
<button type="button" class="clear-button" on:click={clearChoice} aria-label="Clear selection">✕</button>
131+
{/if}
106132
</label>
107133

108134
<datalist id={randomId}>

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)