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

Added component prop to EuiForm #3010

Merged
merged 15 commits into from
Mar 12, 2020
Merged

Added component prop to EuiForm #3010

merged 15 commits into from
Mar 12, 2020

Conversation

anishagg17
Copy link
Contributor

@anishagg17 anishagg17 commented Mar 9, 2020

Summary

Fixes: #2272
EuiForm can now render <form> element too.

Screenshot

Screenshot 2020-03-09 at 2 58 54 PM

Checklist

- [ ] Check against all themes for compatibility in both light and dark modes
- [ ] Checked in mobile

  • Checked in IE11 and Firefox
    - [ ] Props have proper autodocs
  • Added documentation examples
  • Added or updated jest tests
    - [ ] Checked for breaking changes and labeled appropriately
    - [ ] Checked for accessibility including keyboard-only and screenreader modes
  • A changelog entry exists and is marked appropriately

@kibanamachine
Copy link

Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually?

@cchaos
Copy link
Contributor

cchaos commented Mar 9, 2020

@anishagg17 Can you update this PR based on @snide's guidance from the issue: #2272 (comment)

@anishagg17
Copy link
Contributor Author

@cchaos I have made all necessary changes

anishagg17 and others added 5 commits March 11, 2020 03:38
Co-Authored-By: Caroline Horn <549577+cchaos@users.noreply.github.com>
Co-Authored-By: Caroline Horn <549577+cchaos@users.noreply.github.com>
Co-Authored-By: Caroline Horn <549577+cchaos@users.noreply.github.com>
@anishagg17
Copy link
Contributor Author

@cchaos I used exclusive union function but now it fails the tests. Can you please have a look ?

@chandlerprall
Copy link
Contributor

Try with this, @anishagg17

type definition

export type EuiFormProps = CommonProps &
  ExclusiveUnion<
    { component: 'form' } & FormHTMLAttributes<HTMLFormElement>,
    { component?: 'div' } & HTMLAttributes<HTMLDivElement>
  > & {
    isInvalid?: boolean;
    /**
     * Which HTML element to render
     */
    component?: 'form' | 'div';
    error?: ReactNode | ReactNode[];
  };

This specifies FormHTMLAttributes are usable when component = 'form', otherwise HTMLAttributes are usable when component = 'div' | undefined. Verifiable with:

export const Foo = () => {
  return (
    <>
      {/* works */}
      <EuiForm />
      <EuiForm component="div" />
      <EuiForm component="form" />
      <EuiForm component="form" acceptCharset="en" />

      {/* errors */}
      <EuiForm acceptCharset="en" />
      <EuiForm component="div" acceptCharset="en" />
    </>
  );
};

jsx

    <Element className={classes} {...rest as HTMLAttributes<HTMLElement>}>
      {optionalErrorAlert}
      {children}
    </Element>

The casting here is okay as we know everything in the component is setup correctly. Conceptually there is a way to fix this without casting, but TypeScript has (or at least had) a bug deciphering what type the ...rest object is narrowed down to so we can't avoid it anyway.

@anishagg17
Copy link
Contributor Author

thanks for you help 👍

@cchaos
Copy link
Contributor

cchaos commented Mar 12, 2020

Jenkins, test this

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_3010/

Copy link
Contributor

@cchaos cchaos left a comment

Choose a reason for hiding this comment

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

I think this looks good to me with just one more comment for props comment

Co-Authored-By: Caroline Horn <549577+cchaos@users.noreply.github.com>
@cchaos
Copy link
Contributor

cchaos commented Mar 12, 2020

One last, Jenkins, test this

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_3010/

@cchaos cchaos changed the title added renderForm prop to EuiForm Added component prop to EuiForm Mar 12, 2020
@cchaos cchaos merged commit 96de0f1 into elastic:master Mar 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

EuiForm should render to form
5 participants