Skip to content

Commit 74acead

Browse files
author
Samuel Janda
committed
Adopted Standardize props, events, and slots carbon-design-system#1621
1 parent 73fba89 commit 74acead

File tree

1 file changed

+37
-16
lines changed

1 file changed

+37
-16
lines changed

src/TextInput/PasswordInput.svelte

+37-16
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,18 @@
7777
/** Set to `true` to use inline version */
7878
export let inline = false;
7979
80+
/**
81+
* Set HTML attributes on the `label` element
82+
* @type {import('svelte/elements').HTMLLabelAttributes}
83+
*/
84+
export let labelAttributes = {};
85+
86+
/**
87+
* Set HTML attributes on the `input` element
88+
* @type {import('svelte/elements').HTMLInputAttributes}
89+
*/
90+
export let inputAttributes = {};
91+
8092
import { getContext } from "svelte";
8193
import WarningFilled from "../icons/WarningFilled.svelte";
8294
import WarningAltFilled from "../icons/WarningAltFilled.svelte";
@@ -101,9 +113,9 @@
101113
class:bx--text-input-wrapper--light="{light}"
102114
class:bx--text-input-wrapper--inline="{inline}"
103115
on:click
104-
on:mouseover
105-
on:mouseenter
106-
on:mouseleave
116+
on:pointerover
117+
on:pointerenter
118+
on:pointerleave
107119
>
108120
{#if inline}
109121
<label
@@ -114,19 +126,22 @@
114126
class:bx--label--inline="{inline}"
115127
class:bx--label--inline--sm="{inline && size === 'sm'}"
116128
class:bx--label--inline--lg="{inline && (size === 'lg' || size === 'xl')}"
129+
{...labelAttributes}
117130
>
118131
<slot name="labelText">
119132
{labelText}
120133
</slot>
121134
</label>
122-
{#if !isFluid && helperText}
135+
{#if !isFluid && (helperText || $$slots.helperText)}
123136
<div
124137
id="{helperId}"
125138
class:bx--form__helper-text="{true}"
126139
class:bx--form__helper-text--disabled="{disabled}"
127140
class:bx--form__helper-text--inline="{inline}"
128141
>
129-
{helperText}
142+
<slot name="helperText">
143+
{helperText}
144+
</slot>
130145
</div>
131146
{/if}
132147
{/if}
@@ -187,22 +202,22 @@
187202
class:bx--text-input--warning="{warn}"
188203
class:bx--text-input--sm="{size === 'sm'}"
189204
class:bx--text-input--lg="{size === 'lg' || size === 'xl'}"
190-
{...$$restProps}
205+
{...inputAttributes}
191206
on:change
192207
on:input
193-
on:input="{({ target }) => {
194-
value = target.value;
195-
}}"
196208
on:keydown
197209
on:keyup
198210
on:focus
199211
on:blur
200212
on:paste
201213
/>
202-
{#if isFluid && invalid}
214+
{#if isFluid && (invalid || $$slots.invalidText)}
203215
<hr class="bx--text-input__divider" />
204216
<div class="bx--form-requirement" id="{errorId}">
205-
{invalidText}
217+
'
218+
<slot name="invalidText">
219+
{invalidText}
220+
</slot>
206221
</div>
207222
{/if}
208223
{#if !(isFluid && invalid)}
@@ -230,7 +245,9 @@
230245
<span class:bx--assistive-text="{true}">
231246
{#if type === "text"}
232247
{hidePasswordLabel}
233-
{:else}{showPasswordLabel}{/if}
248+
{:else}
249+
{showPasswordLabel}
250+
{/if}
234251
</span>
235252
{/if}
236253
{#if type === "text"}
@@ -241,18 +258,22 @@
241258
</button>
242259
{/if}
243260
</div>
244-
{#if !isFluid && invalid}
261+
{#if !isFluid && (invalid || $$slots.invalidText)}
245262
<div class:bx--form-requirement="{true}" id="{errorId}">
246-
{invalidText}
263+
<slot name="invalidText">
264+
{invalidText}
265+
</slot>
247266
</div>
248267
{/if}
249-
{#if !invalid && !warn && !isFluid && !inline && helperText}
268+
{#if !invalid && !warn && !isFluid && !inline && (helperText || $$slots.helperText)}
250269
<div
251270
class:bx--form__helper-text="{true}"
252271
class:bx--form__helper-text--disabled="{disabled}"
253272
class:bx--form__helper-text--inline="{inline}"
254273
>
255-
{helperText}
274+
<slot name="helperText">
275+
{helperText}
276+
</slot>
256277
</div>
257278
{/if}
258279
{#if !isFluid && !invalid && warn}

0 commit comments

Comments
 (0)