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.

Unable to change focus behavior of `TextInput` / `Selection` components via theme

See original GitHub issue

I would like to great a reusable Grommet theme where the focus-state of Selection and TextInput is a custom color. There is apparently not possible to change this by providing a theme to a Grommet component. It is not possible by using the Grommet Theme Builder.

Perhaps I am not editing the theme correctly, I don’t know.

Behavior

I provide a theme as a prop to the main app component in index.js:

const theme = {  
    "select": {
      "background": "black",
      "container": {},
      "control": {},
      "icons": {},
      "options": {
        "box": {
          "align": "start",
          "pad": "small"
        },
        "text": { "margin": "none" }
      },
      "step": 20,
    },
. . .  /* more custom theme options */
}

ReactDOM.render(
    <Grommet full theme={theme}><App /></Grommet>, 
    document.getElementById('root')
);

Then in App.js:

import React from 'react';
import { Select, Box } from 'grommet';

function App() {
    return (
        <Box>
            <DropSelect options={...} placeholder={...} />
        </Box>
    );
}

function DropSelect(props) {
    const [value, setValue] = React.useState(props.placeholder);
    return (
      <Select
        options={props.options}
        value={value}
        onChange={({ option }) => setValue(option)}
      />
    );
}

Unfocused <DropSelect />: select_no_glow

Focused <DropSelect />: select_glow

I’ve tried providing the theme object with several variations of attempts to change the outline and/or border, as well as attempts to change its style in a focused state. Again, I would like to apply this as a theme to several apps from the highest level possible, without having to do any inline styling.

Any insight would be very helpful.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
IanKBovardcommented, Jan 30, 2020

@clockelliptic Just checking in to see if ShimiSun was able to answer your question.

2reactions
ShimiSuncommented, Nov 25, 2019

Hi @clockelliptic Have you seen this story where you can customize the theme focus color? https://storybook.grommet.io/?path=/story/theme--focus Does that answer your question?

Read more comments on GitHub >

github_iconTop Results From Across the Web

SetFocus function in Power Apps - Microsoft Learn
SetFocus can be used with a control in a scrollbale screen. You cannot set the focus to controls that are within a Container...
Read more >
How to change the focus of text input when using custom text ...
1 Answer 1 ; InputField = React.forwardRef ; const textInput = useRef(null); ; useImperativeHandle(ref, () => ({ // To be able to call...
Read more >
3 ways to autofocus an input in React that ALMOST always work!
This input is focus ed, but no text is selected. If the user starts typing, the text they type will go into that...
Read more >
focus-visible - CSS: Cascading Style Sheets - MDN Web Docs
In this example, the :focus-visible selector uses the UA's behavior to determine when to match. Compare what happens when you click on the ......
Read more >
Control focus with tabindex - web.dev
Standard HTML elements such as <button> or <input> have keyboard accessibility built in for free. If you're building custom interactive ...
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