FormField or TextInput shows focus indicator even when focusIndicator prop is set to false on both
See original GitHub issueExpected Behavior
Focus indicator borders defined in theme should not be visible when focusIndicator
prop is set to false
.
Actual Behavior
Focus indicator borders are visible around: <FormField>
, <TextInput>
and label
Provided codesandbox example is broken for some reason so I will provide relevant code here:
const contentProps: FormFieldProps['contentProps'] = {
focusIndicator: false,
// Toggle background color & border
background: isEditing || isHovered ? colors.backgroundBack : undefined,
direction: 'row',
gap: 'xsmall',
border: {
color: isEditing ? colors.brand : undefined,
},
}
<Form
value={{ [name.current]: newValue }}
onChange={handleTextInputChange}
onSubmit={handleSubmit}
ref={formRef as any}
>
<FormField
{...formFieldProps}
name={name.current}
htmlFor={id.current}
label={label}
contentProps={contentProps}
onClick={handleFormFieldClick}
onBlur={handleFormFieldBlur}
>
<TextInput
{...textInputProps}
id={id.current}
name={name.current}
focusIndicator={false}
color={colors.textStrong}
/>
{isTouched && <Button type="submit" icon={<MdSend size="1.25em" />} plain />}
</FormField>
</Form>
Your Environment
- Grommet version:
^2.14.0
- Browser Name and version:
Brave@Version 1.14.84 Chromium: 85.0.4183.121 (Official Build) (64-bit)
- Operating System and version (desktop or mobile): Windows 10
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
React Native: How to select the next TextInput after pressing ...
The field will be focused as long as this prop is set to true and will not have focus as long as this...
Read more >Remove double focus on some FormField components #4947
Each FormField component has two focus indicators, one for the FormField and the other for the input field. URL, screen shot, or Codepen ......
Read more >focus - CSS: Cascading Style Sheets - MDN Web Docs - Mozilla
The :focus CSS pseudo-class represents an element (such as a form input) that has received focus. It is generally triggered when the user ......
Read more >TextInput - Grommet
A control to input a single line of text, with optional suggestions. ... Whether the plain TextInput should receive a focus outline. boolean....
Read more >Focus on the Next TextInput when Next Keyboard Button is ...
Then we need to add 3 props to our first input returnKeyType , onSubmitEditing , and blurOnSubmit set to false. <TextInput placeholder="First Name" ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
So, for a better explanation, I’ll split this issue in two parts: FormField behavior and TextInput behavior.
This component is based on
<Box>
, thus it receives a focus outline whenonClick
prop is set. Box-kind components can also receivefocusIndicator
prop (differently of input components, those don’t needplain
prop to usefocusIndicator
), and it looks like it’s working as expected.FormField also has a child called
<FormFieldContentBox>
, which wraps the content passed by the user as children of<FormField>
and is also based on<Box>
. The propcontentProps
you’re using controls the properties of<FormFieldContentBox>
and not, for instance, the props of<TextInput>
nor<FormField>
itself. Since this ContentBox is not receiving anonClick
prop, it’s no use passingfocusIndicator
.To achieve what you’re looking for, you should set
focusIndicator
as prop of FormField. Note that it’ll still have a border outline when focused. This can be removed by manually styling it withoutline: 'none';
.I don’t think anything should be changed on grommet components regarding this part of the issue.
TextInput alongside TextArea and MaskedInput make use of an internal styling called
inputStyle
. Right now,focusIndicator
wasn’t working as intended in those components. PR #4753 addresses that, fixing it. Note thatfocusIndicator
prop on inputs should only work when usingplain
prop.IMHO that resolves the issue, but let us know if you still have any unexpected behavior after this.
Even without a working codesandbox example, would you mind providing the component code and custom theming (if there’s any) used to reproduce your screenshot? It might be helpful to anyone who tackles this issue. Thanks 😃