Skip to content
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

chore: add autofill stories #7722

Merged
merged 7 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/@react-spectrum/s2/stories/Form.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ export const Example = (args: any) => (
<TextField label="First Name" name="firstName" />
<TextField label="Last Name" name="firstName" />
<TextField label="Email" name="email" type="email" description="Enter an email" />
<Picker label="Country" name="country">
<PickerItem id="canada">Canada</PickerItem>
<PickerItem id="united-states">United States</PickerItem>
<PickerItem id="mexico">Mexico</PickerItem>
<PickerItem id="argentina">Argentina</PickerItem>
</Picker>
<CheckboxGroup label="Favorite sports">
<Checkbox value="soccer">Soccer</Checkbox>
<Checkbox value="baseball">Baseball</Checkbox>
Expand Down
67 changes: 67 additions & 0 deletions packages/react-aria-components/stories/Form.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright 2022 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/

import {action} from '@storybook/addon-actions';
import {Button, Form, Input, Label, ListBox, ListBoxItem, Popover, Select, SelectValue, TextField} from 'react-aria-components';
import React from 'react';

export default {
title: 'React Aria Components'
};


export const FormAutoFillExample = () => {
return (
<Form
aria-label="Shipping information"
onSubmit={e => {
action('onSubmit')(Object.fromEntries(new FormData(e.target as HTMLFormElement).entries()));
e.preventDefault();
}}>
<TextField>
<Label>Address</Label>
<Input name="streetAddress" type="text" id="streetAddress" autoComplete="shipping street-address" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

huh strange. it looks like it has autocomplete=""shipping address-level2" based on the screenshot. does it not autofill for you either?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, node above that one

Copy link
Member Author

@yihuiliao yihuiliao Feb 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh my b. that's really weird because it appears for me. it should be valid since i see an example of it in the mdn docs...it might be good to see if another person can reproduce

do you see this in other browsers as well?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

huh, well, i updated chrome last night. now it's rendering. My Chrome autofill works on it, but my Dashlane doesn't recognize it for some reason still. At this point though, I think it's correct and I'm just running into local issues

</TextField>
<TextField>
<Label>City</Label>
<Input name="city" type="text" id="city" autoComplete="shipping address-level2" />
</TextField>
<TextField>
<Label>State</Label>
<Input name="state" type="text" id="state" autoComplete="shipping address-level1" />
</TextField>
<TextField>
<Label>Zip</Label>
<Input name="city" type="text" id="city" autoComplete="shipping postal-code" />
</TextField>
<Select name="country" id="country" autoComplete="shipping country">
<Label>Country</Label>
<Button>
<SelectValue />
<span aria-hidden="true">▼</span>
</Button>
<Popover>
<ListBox>
<ListBoxItem>Greece</ListBoxItem>
<ListBoxItem>Italy</ListBoxItem>
<ListBoxItem>Spain</ListBoxItem>
<ListBoxItem>Mexico</ListBoxItem>
<ListBoxItem>Canada</ListBoxItem>
<ListBoxItem>United States</ListBoxItem>
</ListBox>
</Popover>
</Select>
<Button type="submit">Submit</Button>
</Form>
);
};