Skip to content

Commit b71f2e3

Browse files
committed
✨ Add HTML Support to input labels
1 parent 8406ae2 commit b71f2e3

File tree

5 files changed

+11
-4
lines changed

5 files changed

+11
-4
lines changed

src/components/Input/Input.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const useLabel = !!(label || subText || Astro.slots.has('default'))
3434
<ConditionalWrapper condition={useLabel}>
3535
<label slot="wrapper" class:list={labelClasses}>
3636
{label && (
37-
<div class={styles.label}>{label}</div>
37+
<div class={styles.label} set:html={label} />
3838
)}
3939
<ConditionalWrapper condition={Astro.slots.has('default')}>
4040
<div class={styles.wrapper} slot="wrapper">

src/components/Input/Input.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@
4848
>
4949
<slot />
5050
<input
51-
{...{ type }}
5251
class={classes}
5352
bind:value
5453
on:change={onChange}
5554
on:keyup={onKeyUp}
5655
on:input={onInput}
5756
on:click={onClick}
57+
{...{ type }}
5858
{...$$restProps}
5959
/>
6060
</ConditionalWrapper>

src/components/Input/Input.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ const Input = ({
3838
</label>
3939
)}>
4040
{label && (
41-
<div className={styles.label}>{label}</div>
41+
<div
42+
className={styles.label}
43+
dangerouslySetInnerHTML={{ __html: label }}
44+
/>
4245
)}
4346
<ConditionalWrapper condition={!!children} wrapper={children => (
4447
<div className={styles.wrapper}>

src/pages/components/input.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ const sections = getSections({
9898
</ComponentWrapper>
9999

100100
<ComponentWrapper title="Input with label">
101-
<section.component label="Name" />
101+
<section.component label="Average miles driven <b>per week</b>" />
102102
</ComponentWrapper>
103103

104104
<ComponentWrapper title="Label and sub text">

src/playground/SveltePlayground.svelte

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
let radio = ''
4545
let toggle = false
4646
let input = ''
47+
let inputBinding = ''
4748
let slider = 50
4849
let wordCount = 0
4950
let select = ''
@@ -138,6 +139,7 @@
138139

139140
<Card title="Input">
140141
<Input
142+
bind:value={inputBinding}
141143
label="Enter a value"
142144
placeholder="Or change the color below"
143145
onKeyUp={e => input = e.currentTarget.value}
@@ -148,6 +150,8 @@
148150
onChange={e => input = e.currentTarget.value}
149151
/>
150152

153+
<p>Binding: {inputBinding}</p>
154+
151155
<span class={styles.span}>{input}</span>
152156
</Card>
153157

0 commit comments

Comments
 (0)