mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-14 18:01:06 +00:00
refactor(search): remove dispatch, rename placeHolderText
This commit is contained in:
parent
f75e3264cc
commit
24c44ad41b
3 changed files with 12 additions and 8 deletions
|
@ -6,6 +6,14 @@
|
||||||
import SearchSkeleton from './Search.Skeleton.svelte';
|
import SearchSkeleton from './Search.Skeleton.svelte';
|
||||||
|
|
||||||
let value = '';
|
let value = '';
|
||||||
|
|
||||||
|
$: {
|
||||||
|
if (!value.length) {
|
||||||
|
console.log('cleared');
|
||||||
|
} else {
|
||||||
|
console.log('value', value);
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Layout>
|
<Layout>
|
||||||
|
|
|
@ -20,7 +20,7 @@ export const Default = () => ({
|
||||||
'The label text for the close button (closeButtonLabelText)',
|
'The label text for the close button (closeButtonLabelText)',
|
||||||
'Clear search input'
|
'Clear search input'
|
||||||
),
|
),
|
||||||
placeHolderText: text('Placeholder text (placeHolderText)', 'Search')
|
placeholder: text('Placeholder text (placeholder)', 'Search')
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
export let autofocus = false;
|
export let autofocus = false;
|
||||||
export let type = 'text';
|
export let type = 'text';
|
||||||
export let small = false;
|
export let small = false;
|
||||||
export let placeHolderText = '';
|
export let placeholder = '';
|
||||||
export let labelText = '';
|
export let labelText = '';
|
||||||
export let closeButtonLabelText = 'Clear search input';
|
export let closeButtonLabelText = 'Clear search input';
|
||||||
export let size = small ? 'sm' : 'xl';
|
export let size = small ? 'sm' : 'xl';
|
||||||
|
@ -13,14 +13,11 @@
|
||||||
export let id = Math.random();
|
export let id = Math.random();
|
||||||
export let style = undefined;
|
export let style = undefined;
|
||||||
|
|
||||||
import { createEventDispatcher } from 'svelte';
|
|
||||||
import Search16 from 'carbon-icons-svelte/lib/Search16';
|
import Search16 from 'carbon-icons-svelte/lib/Search16';
|
||||||
import Close16 from 'carbon-icons-svelte/lib/Close16';
|
import Close16 from 'carbon-icons-svelte/lib/Close16';
|
||||||
import Close20 from 'carbon-icons-svelte/lib/Close20';
|
import Close20 from 'carbon-icons-svelte/lib/Close20';
|
||||||
import { cx } from '../../lib';
|
import { cx } from '../../lib';
|
||||||
|
|
||||||
const dispatch = createEventDispatcher();
|
|
||||||
|
|
||||||
let inputRef = undefined;
|
let inputRef = undefined;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -34,7 +31,6 @@
|
||||||
bind:this={inputRef}
|
bind:this={inputRef}
|
||||||
role="searchbox"
|
role="searchbox"
|
||||||
class={cx('--search-input')}
|
class={cx('--search-input')}
|
||||||
placeholder={placeHolderText}
|
|
||||||
on:change
|
on:change
|
||||||
on:input
|
on:input
|
||||||
on:input={({ target }) => {
|
on:input={({ target }) => {
|
||||||
|
@ -43,14 +39,14 @@
|
||||||
{autofocus}
|
{autofocus}
|
||||||
{type}
|
{type}
|
||||||
{id}
|
{id}
|
||||||
{value} />
|
{value}
|
||||||
|
{placeholder} />
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
class={cx('--search-close', value === '' && '--search-close--hidden')}
|
class={cx('--search-close', value === '' && '--search-close--hidden')}
|
||||||
on:click
|
on:click
|
||||||
on:click={() => {
|
on:click={() => {
|
||||||
value = '';
|
value = '';
|
||||||
dispatch('change', value);
|
|
||||||
inputRef.focus();
|
inputRef.focus();
|
||||||
}}
|
}}
|
||||||
aria-label={closeButtonLabelText}>
|
aria-label={closeButtonLabelText}>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue