Skip to content

Commit eb8ac19

Browse files
authored
Merge pull request #262 from silinternational/feature/fix-MoneyInput-icons
fix(TextInputs): use latest material docs to fix icon spacing issues …
2 parents 2fc856d + 2e503e0 commit eb8ac19

File tree

3 files changed

+37
-65
lines changed

3 files changed

+37
-65
lines changed

components/mdc/TextInput/MoneyInput.svelte

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ $: valueNotDivisibleByStep =
5454
(internalValue && (internalValue / Number(step)).toFixed(2) % 1 !== 0) || valueHasTooManyDecPlaces
5555
$: internalValue = Number(value) || 0
5656
$: warn = showWarn
57+
$: value, addOrRemoveInvalidClass(error, element)
5758
$: addOrRemoveInvalidClass(showError || showWarn, element)
5859
5960
onMount(() => {
@@ -66,31 +67,29 @@ afterUpdate(() => (width = `${element?.offsetWidth}px`))
6667
const focus = (node) => autofocus && node.focus()
6768
</script>
6869
69-
<style>
70-
.material-icons {
71-
color: rgb(133, 140, 148);
72-
position: relative;
73-
top: 0.4rem;
74-
right: 0.6rem;
75-
}
76-
.label-margin {
77-
margin-left: 1.1rem;
78-
}
79-
.mdc-text-field--label-floating .mdc-floating-label {
80-
margin-left: 0;
81-
}
82-
</style>
83-
8470
<label
85-
class="mdc-text-field mdc-text-field--outlined {$$props.class || ''} textfield-radius"
71+
class="mdc-text-field mdc-text-field--outlined mdc-text-field--with-leading-icon {$$props.class ||
72+
''} textfield-radius"
8673
class:mdc-text-field--no-label={!label}
8774
class:mdc-text-field--disabled={disabled}
88-
class:mdc-text-field--invalid={error}
8975
class:warn
9076
class:showError
9177
bind:this={element}
9278
>
93-
<i class="material-icons mdc-text-field__icon--leading" class:error aria-hidden="true">attach_money</i>
79+
<span class="mdc-notched-outline">
80+
<span class="mdc-notched-outline__leading" />
81+
{#if label}
82+
<span class="mdc-notched-outline__notch">
83+
<span class="mdc-floating-label" class:error id={labelID}>
84+
{label}
85+
</span>
86+
</span>
87+
{/if}
88+
<span class="mdc-notched-outline__trailing" />
89+
</span>
90+
<i class="material-icons mdc-text-field__icon mdc-text-field__icon--leading" class:error aria-hidden="true">
91+
attach_money
92+
</i>
9493
<input
9594
{step}
9695
type="number"
@@ -115,21 +114,8 @@ const focus = (node) => autofocus && node.focus()
115114
{required}
116115
/>
117116
{#if showErrorIcon}
118-
<span class="mdc-text-field__affix mdc-text-field__affix--suffix">
119-
<i class="material-icons error" aria-hidden="true"> error</i>
120-
</span>
117+
<i class="material-icons mdc-text-field__icon mdc-text-field__icon--trailing error" aria-hidden="true"> error</i>
121118
{/if}
122-
<span class="mdc-notched-outline">
123-
<span class="mdc-notched-outline__leading" />
124-
{#if label}
125-
<span class="mdc-notched-outline__notch">
126-
<span class="mdc-floating-label label-margin" class:error id={labelID}>
127-
{label}
128-
</span>
129-
</span>
130-
{/if}
131-
<span class="mdc-notched-outline__trailing" />
132-
</span>
133119
</label>
134120
<div class="mdc-text-field-helper-line" style="width: {width};">
135121
<div

components/mdc/TextInput/TextField.svelte

Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ $: hasExceededMaxLength = maxlength && value.length > maxlength
4343
$: error = hasExceededMaxLength || (hasFocused && hasBlurred && required && !value)
4444
$: warn = showWarn
4545
$: showCounter = maxlength && value.length / maxlength > 0.85
46-
$: value && addOrRemoveInvalidClass(error, element)
46+
$: value, addOrRemoveInvalidClass(error, element)
4747
$: addOrRemoveInvalidClass(showError || showWarn, element)
4848
4949
onMount(() => {
@@ -58,30 +58,31 @@ afterUpdate(() => {
5858
const focus = (node) => autofocus && node.focus()
5959
</script>
6060
61-
<style>
62-
.material-icons {
63-
color: rgb(133, 140, 148);
64-
position: relative;
65-
top: 0.4rem;
66-
right: 0.6rem;
67-
}
68-
.label-margin {
69-
margin-left: 1.1rem;
70-
}
71-
.mdc-text-field--label-floating .mdc-floating-label {
72-
margin-left: 0;
73-
}
74-
</style>
75-
7661
<label
7762
class="mdc-text-field mdc-text-field--outlined {$$props.class || ''} textfield-radius"
7863
class:mdc-text-field--no-label={!label}
7964
class:mdc-text-field--disabled={disabled}
8065
class:warn
8166
class:showError
67+
class:mdc-text-field--with-leading-icon={icon}
8268
bind:this={element}
8369
>
84-
<i class="material-icons mdc-text-field__icon--leading" class:error aria-hidden="true"> {icon}</i>
70+
<span class="mdc-notched-outline">
71+
<span class="mdc-notched-outline__leading" />
72+
{#if label}
73+
<span class="mdc-notched-outline__notch">
74+
<span class="mdc-floating-label" class:error id={labelID}>
75+
{label}
76+
</span>
77+
</span>
78+
{/if}
79+
<span class="mdc-notched-outline__trailing" />
80+
</span>
81+
{#if icon}
82+
<i class="material-icons mdc-text-field__icon mdc-text-field__icon--leading" class:error aria-hidden="true">
83+
{icon}</i
84+
>
85+
{/if}
8586
<input
8687
type="text"
8788
class="mdc-text-field__input"
@@ -104,22 +105,8 @@ const focus = (node) => autofocus && node.focus()
104105
{placeholder}
105106
/>
106107
{#if hasExceededMaxLength}
107-
<span class="mdc-text-field__affix mdc-text-field__affix--suffix"
108-
><i class="material-icons mdc-text-field__icon--trailing error" aria-hidden="true">error</i></span
109-
>
108+
<i class="material-icons mdc-text-field__icon mdc-text-field__icon--trailing error" aria-hidden="true">error</i>
110109
{/if}
111-
112-
<span class="mdc-notched-outline">
113-
<span class="mdc-notched-outline__leading" />
114-
{#if label}
115-
<span class="mdc-notched-outline__notch">
116-
<span class="mdc-floating-label" class:label-margin={icon} class:error id={labelID}>
117-
{label}
118-
</span>
119-
</span>
120-
{/if}
121-
<span class="mdc-notched-outline__trailing" />
122-
</span>
123110
</label>
124111
<div class="mdc-text-field-helper-line" style="width: {width};">
125112
<div

stories/MoneyInput.stories.svelte

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ const args = {
1515
'on:keypress': (event) => (lastKey = event.key),
1616
'on:keyup': (event) => console.log('keyup', event),
1717
class: '', //will only work with global class
18-
maxValue: 100,
1918
step: '.01',
2019
}
2120
$: arrayOfValues.forEach((v) =>

0 commit comments

Comments
 (0)