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

Add optional property labelId to formItem, to be able to set the id of the generated <label/> tag. #31095

Open
1 task
luko0610 opened this issue Jun 22, 2021 · 0 comments
Labels

Comments

@luko0610
Copy link

  • I have searched the issues of this repository and believe that this is not a duplicate.

What problem does this feature solve?

I am currently in the situation, where I want to use the aria-labelledBy attribute on an , to correctly associate the with it's label.
The aria-labelledby attribute requires the label to have an id set.

In general form labels in ant design don't seem to have the id attribute set, which also causes issues when using automated testing frameworks.
In this case to make the whole thing work I'd need a possibility to set the id on the generated .

What does the proposed API look like?

I'd suggest adding a labelId attribute to the <Form.Item/>, enabling the developer to set an id to the label tag.
If no labelId is provided I'd default to something like lbl_${formName}_{formItemName}.

Suggestion:

 <Form.Item
        label="Username"
        labelId="lbl_username"
        name="username"
        rules={[
          {
            required: true,
            message: 'Please input your username!',
          },
        ]}
      >
        <Input />
      </Form.Item>

The labelId parameter is then applied to the generated label tag.

Another more generic possibility would be to add a labelProps property, which is an object of attributes, that are then applied to the label tag.

 <Form.Item
        label="Username"
        labelProps: { id: "lbl_username" }
        name="username"
        rules={[
          {
            required: true,
            message: 'Please input your username!',
          },
        ]}
      >
        <Input />
      </Form.Item>

I'd prefer the second solution, as this would allow developers to set whatever attribute they want ont the .

I'm happy to discuss the issue. If this is an acceptable change let me know and I can make a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant