Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add(SearchableSelect): add clear button to SearchableSelect #288

Merged
merged 3 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
# Changelog

All notable changes to this project will be documented in this file.
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).

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


### Added

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

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


### Fixed

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

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

Expand Down
28 changes: 27 additions & 1 deletion components/custom/SearchableSelect/SearchableSelect.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export let showError = false

let element = {}
let randomId = generateRandomID('dataList-')
let savedChoice = ''

const dispatch = createEventDispatcher()

Expand All @@ -32,6 +33,18 @@ const onChange = (e) => {
choice = internalChoice
element.blur()
}

const clearChoice = () => {
savedChoice = choice
choice = ''
}

const onBlur = () => {
if (savedChoice && !choice) {
choice = savedChoice
}
dispatch('check', choice)
forevermatt marked this conversation as resolved.
Show resolved Hide resolved
}
</script>

<style>
Expand Down Expand Up @@ -80,6 +93,16 @@ const onChange = (e) => {
border-color: var(--mdc-theme-status-error, var(--mdc-theme-error));
color: var(--mdc-theme-status-error, var(--mdc-theme-error));
}

.clear-button {
cursor: pointer;
padding: 5px;
position: relative;
right: 50px;
border-radius: 4px;
border: none;
background-color: transparent;
}
</style>

<label class="custom-field" style="--field-padding: {padding}; {$$props.class || ''}">
Expand All @@ -98,11 +121,14 @@ const onChange = (e) => {
value={choice}
on:change={onChange}
on:change
on:blur={(e) => dispatch('check', e.target.value)}
on:blur={onBlur}
on:blur
on:focus
/>
<span class="placeholder">{placeholder}</span>
{#if choice}
<button type="button" class="clear-button" on:click={clearChoice} aria-label="Clear selection">✕</button>
{/if}
</label>

<datalist id={randomId}>
Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.