-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add autocomplete attribute #213
Open
felipefreitag
wants to merge
2
commits into
main
Choose a base branch
from
add-autocomplete-attribute
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
117 changes: 117 additions & 0 deletions
117
apps/web/app/routes/test-examples/field-with-autocomplete.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
import hljs from 'highlight.js/lib/common' | ||
import type { | ||
ActionFunction, | ||
LoaderFunction, | ||
MetaFunction, | ||
} from '@remix-run/node' | ||
import { formAction } from '~/formAction' | ||
import { z } from 'zod' | ||
import Form from '~/ui/form' | ||
import { metaTags } from '~/helpers' | ||
import { makeDomainFunction } from 'domain-functions' | ||
import Example from '~/ui/example' | ||
|
||
const title = 'Field with autocomplete' | ||
const description = | ||
'In this example, we pass a autocomplete prop to a field without children.' | ||
|
||
export const meta: MetaFunction = () => metaTags({ title, description }) | ||
|
||
const schema = z.object({ | ||
name: z.string().min(1), | ||
code: z.number().int().optional(), | ||
organization: z.string().optional(), | ||
organizationTitle: z.enum(['director', 'manager', 'employee']), | ||
streetAddress: z.string().optional(), | ||
country: z.string().optional(), | ||
postalCode: z.string().optional(), | ||
addressLine1: z.string().optional(), | ||
}) | ||
|
||
export const loader: LoaderFunction = () => ({ | ||
code: hljs.highlight('', { language: 'ts' }).value, | ||
}) | ||
|
||
const mutation = makeDomainFunction(schema)(async (values) => values) | ||
|
||
export const action: ActionFunction = async ({ request }) => | ||
formAction({ request, schema, mutation }) | ||
|
||
export default function Component() { | ||
return ( | ||
<Example title={title} description={description}> | ||
<Form schema={schema}> | ||
{({ Field, Errors, Button }) => ( | ||
<> | ||
{/* Text field */} | ||
<Field name="name" autoComplete="name" /> | ||
{/* Numeric field */} | ||
<Field name="code"> | ||
{({ Label, Input, Errors }) => ( | ||
<> | ||
<Label>Code</Label> | ||
<Input type="number" autoComplete="one-time-code" /> | ||
<Errors /> | ||
</> | ||
)} | ||
</Field> | ||
{/* Select field */} | ||
<Field name="organizationTitle" autoComplete="organization-title" /> | ||
{/* Textarea field */} | ||
<Field | ||
name="streetAddress" | ||
multiline | ||
autoComplete="street-address" | ||
/> | ||
{/* Text field child */} | ||
<Field name="organization" autoComplete="organization"> | ||
{({ Label, Input, Errors }) => ( | ||
<> | ||
<Label>Organization</Label> | ||
<Input autoComplete="organization" /> | ||
<Errors /> | ||
</> | ||
)} | ||
</Field> | ||
{/* Smart input child*/} | ||
<Field name="country"> | ||
{({ Label, SmartInput, Errors }) => ( | ||
<> | ||
<Label>Country</Label> | ||
<SmartInput autoComplete="country" /> | ||
<Errors /> | ||
</> | ||
)} | ||
</Field> | ||
{/* Select child */} | ||
<Field name="postalCode"> | ||
{({ Label, Select, Errors }) => ( | ||
<> | ||
<Label>Postal code</Label> | ||
<Select autoComplete="postal-code"> | ||
<option value="12345">12345</option> | ||
<option value="67890">67890</option> | ||
</Select> | ||
<Errors /> | ||
</> | ||
)} | ||
</Field> | ||
{/* Textarea child */} | ||
<Field name="addressLine1"> | ||
{({ Label, Multiline, Errors }) => ( | ||
<> | ||
<Label>Postal code</Label> | ||
<Multiline autoComplete="address-line1" /> | ||
|
||
<Errors /> | ||
</> | ||
)} | ||
</Field> | ||
<Errors /> | ||
<Button /> | ||
</> | ||
)} | ||
</Form> | ||
</Example> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,5 +63,8 @@ | |
}, | ||
"engines": { | ||
"node": ">=14" | ||
}, | ||
"volta": { | ||
"node": "18.16.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
apps/web/tests/examples/forms/field-with-autocomplete.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { test, expect } from 'tests/setup/tests' | ||
|
||
const route = '/test-examples/field-with-autocomplete' | ||
|
||
test('With JS enabled', async ({ example }) => { | ||
const { page } = example | ||
|
||
const name = example.field('name') | ||
const code = example.field('code') | ||
const organizationTitle = example.field('organizationTitle') | ||
const organization = example.field('organization') | ||
const streetAddress = example.field('streetAddress') | ||
const country = example.field('country') | ||
const postalCode = example.field('postalCode') | ||
const addressLine1 = example.field('addressLine1') | ||
|
||
await page.goto(route) | ||
|
||
await expect(name.input).toHaveAttribute('autocomplete', 'name') | ||
await expect(code.input).toHaveAttribute('autocomplete', 'one-time-code') | ||
await expect(organizationTitle.input).toHaveAttribute( | ||
'autocomplete', | ||
'organization-title', | ||
) | ||
await expect(streetAddress.input).toHaveAttribute( | ||
'autocomplete', | ||
'street-address', | ||
) | ||
await expect(organization.input).toHaveAttribute( | ||
'autocomplete', | ||
'organization', | ||
) | ||
await expect(country.input).toHaveAttribute('autocomplete', 'country') | ||
await expect(postalCode.input).toHaveAttribute('autocomplete', 'postal-code') | ||
await expect(addressLine1.input).toHaveAttribute( | ||
'autocomplete', | ||
'address-line1', | ||
) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't find a more specific type, I accept suggestions here