Skip to content

Commit bec248c

Browse files
committed
feat: Add autocorrect and spellcheck props to TextField
1 parent cd77e2e commit bec248c

3 files changed

Lines changed: 37 additions & 0 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@layerstack/ui': minor
3+
---
4+
5+
feat(TextField): Add `autocorrect` and `spellcheck` props (along existing `autocapitalize`)

‎packages/ui/src/lib/components/TextField.ssr.test.ts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,26 @@ describe('TextField (SSR)', () => {
2222
expect(body).not.toContain('<input');
2323
});
2424

25+
it('passes the keyboard attributes to the input', () => {
26+
const { body } = render(TextField, {
27+
props: { autocapitalize: 'off', autocorrect: 'off', spellcheck: false },
28+
});
29+
30+
expect(body).toMatch(/<input[^>]*autocapitalize="off"/);
31+
expect(body).toMatch(/<input[^>]*autocorrect="off"/);
32+
expect(body).toMatch(/<input[^>]*spellcheck="false"/);
33+
});
34+
35+
it('passes the keyboard attributes to the textarea', () => {
36+
const { body } = render(TextField, {
37+
props: { multiline: true, autocapitalize: 'off', autocorrect: 'off', spellcheck: false },
38+
});
39+
40+
expect(body).toMatch(/<textarea[^>]*autocapitalize="off"/);
41+
expect(body).toMatch(/<textarea[^>]*autocorrect="off"/);
42+
expect(body).toMatch(/<textarea[^>]*spellcheck="false"/);
43+
});
44+
2545
it('renders the initial value', () => {
2646
const { body } = render(TextField, { props: { value: 'hello' } });
2747

‎packages/ui/src/lib/components/TextField.svelte‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@
8585
accept?: string | RegExp;
8686
/** https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/autocapitalize */
8787
autocapitalize?: InputProps['autocapitalize'];
88+
/** Safari only. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#autocorrect */
89+
autocorrect?: InputProps['autocorrect'];
90+
/** https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/spellcheck */
91+
spellcheck?: InputProps['spellcheck'];
8892
role?: AriaRole;
8993
9094
/** see: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#min */
@@ -167,6 +171,8 @@
167171
replace,
168172
accept,
169173
autocapitalize,
174+
autocorrect,
175+
spellcheck,
170176
role,
171177
min,
172178
max,
@@ -442,6 +448,8 @@
442448
{/if}
443449

444450
{#if multiline}
451+
<!-- `autocorrect` is spread because `svelte/elements` types it for `<input>` alone,
452+
while Safari honours it on a `<textarea>` as well -->
445453
<textarea
446454
{id}
447455
{name}
@@ -451,6 +459,8 @@
451459
{disabled}
452460
value={inputValue}
453461
{autocapitalize}
462+
{spellcheck}
463+
{...{ autocorrect }}
454464
bind:this={inputEl}
455465
oninput={handleInput}
456466
{onfocus}
@@ -475,6 +485,8 @@
475485
{replace}
476486
{accept}
477487
{autocapitalize}
488+
{autocorrect}
489+
{spellcheck}
478490
{min}
479491
{max}
480492
step={resolvedStep}

0 commit comments

Comments
 (0)