Skip to content

Commit 4e7c609

Browse files
authored
Add disabled property to input with styling and condition (#25)
1 parent 64f35ec commit 4e7c609

File tree

4 files changed

+13
-1
lines changed

4 files changed

+13
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## Next
4+
- Add `disabled` property
5+
36
## 2.1.1 - 2022 Aug 15
47
- Fix broken month dropdown on Firefox
58
- Fix unreliable clamping to min/max dates

src/lib/DateInput.svelte

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
export let placeholder = '2020-12-31 23:00:00'
4545
/** Whether the text is valid */
4646
export let valid = true
47+
/** Disable the input **/
48+
export let disabled = false
4749
4850
/** Format string */
4951
export let format = 'yyyy-MM-dd HH:mm:ss'
@@ -145,11 +147,12 @@
145147
type="text"
146148
bind:value={text}
147149
{placeholder}
150+
{disabled}
148151
on:focus={() => (visible = true)}
149152
on:mousedown={() => (visible = true)}
150153
on:input={input}
151154
/>
152-
{#if visible}
155+
{#if visible && !disabled}
153156
<div class="picker" class:visible transition:fly={{ duration: 80, easing: cubicInOut, y: -5 }}>
154157
<DateTimePicker
155158
on:focusout={onFocusOut}
@@ -182,6 +185,8 @@
182185
&:focus
183186
border-color: var(--date-picker-highlight-border, #0269f7)
184187
box-shadow: 0px 0px 0px 2px var(--date-picker-highlight-shadow, rgba(#0269f7, 0.4))
188+
&:disabled
189+
opacity: 0.5
185190
.invalid
186191
border: 1px solid rgba(#f92f72, 0.5)
187192
background-color: rgba(#f92f72, 0.1)

src/routes/_DateInput.svelte

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
let max: Date
1010
let valid: boolean
1111
let visible: boolean
12+
let disabled: boolean
1213
let closeOnSelection: boolean
1314
let browseWithoutSelecting: boolean
1415
let format: string
@@ -24,6 +25,7 @@
2425
bind:valid
2526
bind:format
2627
bind:visible
28+
bind:disabled
2729
bind:closeOnSelection
2830
bind:browseWithoutSelecting
2931
/>
@@ -37,6 +39,7 @@
3739
<Prop label="valid" bind:value={valid} />
3840
<Prop label="format" bind:value={format} />
3941
<Prop label="visible" bind:value={visible} />
42+
<Prop label="disabled" bind:value={disabled} />
4043
<Prop label="closeOnSelection" bind:value={closeOnSelection} />
4144
<Prop label="browseWithoutSelecting" bind:value={browseWithoutSelecting} />
4245
<Prop label="locale">Default</Prop>

src/routes/docs.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ The component will not assign a date value until a specific date is selected in
3838
| `valid` | bool | Whether the text is valid |
3939
| `format` | string | Format string |
4040
| `visible` | bool | Whether the date popup is visible |
41+
| `disabled` | bool | Disable the input |
4142
| `closeOnSelection` | bool | Close the date popup when a date is selected |
4243
| `browseWithoutSelecting` | bool | Wait with updating the date until a date is selected |
4344
| `locale` | Locale | Locale object for internationalization |

0 commit comments

Comments
 (0)