Skip to content

Commit 568f659

Browse files
committed
feat(TextField): Add icon prop
1 parent fa3aa85 commit 568f659

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

components/mdc/TextInput/TextField.svelte

+15-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export let maxlength = undefined
1111
export let autofocus = false
1212
export let disabled = false
1313
export let required = false
14+
export let icon = ''
1415
1516
const labelID = generateRandomID('text-label-')
1617
@@ -28,12 +29,24 @@ const focus = (node) => autofocus && node.focus()
2829
</script>
2930

3031
<style>
32+
.material-icons {
33+
color: rgb(133, 140, 148);
34+
position: relative;
35+
top: 0.4rem;
36+
right: 0.6rem;
37+
}
3138
.required {
3239
color: var(--mdc-required-input, var(--mdc-theme-status-error));
3340
font-size: small;
3441
margin-left: 1rem;
3542
margin-top: 0.2rem;
3643
}
44+
.label-margin {
45+
margin-left: 1.1rem;
46+
}
47+
.mdc-text-field--label-floating .mdc-floating-label {
48+
margin-left: 0;
49+
}
3750
</style>
3851

3952
<label
@@ -42,6 +55,7 @@ const focus = (node) => autofocus && node.focus()
4255
class:mdc-text-field--disabled={disabled}
4356
bind:this={element}
4457
>
58+
<i class="material-icons" aria-hidden="true">{icon}</i>
4559
<input
4660
type="text"
4761
class="mdc-text-field__input"
@@ -61,7 +75,7 @@ const focus = (node) => autofocus && node.focus()
6175
<span class="mdc-notched-outline__leading" />
6276
{#if label}
6377
<span class="mdc-notched-outline__notch">
64-
<span class="mdc-floating-label" id={labelID}>
78+
<span class="mdc-floating-label" class:label-margin={icon} id={labelID}>
6579
{label}
6680
</span>
6781
</span>

stories/TextField.stories.svelte

+4
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,7 @@ let lastKey = ''
3434
<Story name="Autofocus" args={copyAndModifyArgs(args, { autofocus: true })} />
3535

3636
<Story name="Disabled" args={copyAndModifyArgs(args, { disabled: true })} />
37+
38+
<Story name="maxlength" args={copyAndModifyArgs(args, { maxlength: 50 })} />
39+
40+
<Story name="icon" args={copyAndModifyArgs(args, { icon: 'home' })} />

0 commit comments

Comments
 (0)