question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

FormField render render a border for children input inside custom component

See original GitHub issue

When I use a custom component, with an input field, as child of a FormField I have the bottom border from FormField and the full border from the input field.

Here an example using a composed field for password input and a plain TextInput

https://codesandbox.io/s/wrong-border-for-form-field-bbyuf

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
ShimiSuncommented, Apr 1, 2020

Thanks for reporting guys, just to make sure you know you can remove the border from the theme https://v2.grommet.io/formfield#formField.border.side, but I’m aware it will affect all of your FormFields and not just the custom component one.

This issue makes me think we need to consider a border prop on the FormField component and not just on the theme.

0reactions
megothsscommented, Aug 10, 2021

The FormField component is testing the displayName property of the child component to decide the style of the border / padding:

const grommetInputNames = [
  'CheckBox',
  'CheckBoxGroup',
  'TextInput',
  'Select',
  'MaskedInput',
  'TextArea',
  'DateInput',
  'FileInput',
  'RadioButtonGroup',
];
    let contents =
      (themeBorder &&
        children &&
        Children.map(children, (child) => {
          if (
            child &&
            child.type &&
            grommetInputPadNames.indexOf(child.type.displayName) !== -1
          ) {
            wantContentPad = true;
          }
          if (
            child &&
            child.type &&
            grommetInputNames.indexOf(child.type.displayName) !== -1 &&
            child.props.plain === undefined &&
            child.props.focusIndicator === undefined
          ) {
            return cloneElement(child, {
              plain: true,
              focusIndicator: false,
            });
          }
          return child;
        })) ||
      children;

As a workaround it is possible to rename the displayName property of the custom component to one in the list that it is tested. Something like the code below:

export const CustomSelect = ({disabled, loading, ...props}) => {
  return (
    <Select
      {...props}
      icon={loading ? <Spinner /> : <FormDown />}
      disabled={disabled || loading}
      dropHeight="medium"
      ...
    />
  );
};

CustomSelect.displayName = 'Select';

It would be nice if we could provide a custom property to let Grommet know that the custom component should be treated as an input. CustomComponent.isGrommetInput = true for example.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ASP.NET Core Blazor forms and input components
For input components in a form with an EditContext, the default validation behavior includes updating the field CSS class to reflect the field's ......
Read more >
Change style of existing input fields whenever error occurs in ...
As of now there doesn't seem to be an easy way to do this. You can render a custom children for <Field> to...
Read more >
How to create reusable form components with React Hook ...
The first step is to create an input component. Creating an isolated component can be a good way to provide consumers of your...
Read more >
<Field /> | Formik
In Formik 0.9 to 1.x, the render prop could also be used for rendering. ... input; select; textarea; A valid HTML element name;...
Read more >
Create and style a text field - Flutter documentation
Text fields allow users to type text into an app. They are used to build forms, send messages, create search experiences, and more....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found