React focus items list in child component after action from a different child component












1

















EDIT: While Sung Kim's answer is correct for the original scenario, I forgot to add that this behaviour (of selecting the next item from the list) can be toggled by some other key, for instance ArrowDown, in which case the tabIndex would not be of much help initially at least.



`````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````



I'm trying to work on a dropdown component that has two separate (sibling) functional components. The first one is a regular <input> that will take in a value.
The second one is a <ul> that will display the results.



The flow is that initially only the <input> is displayed, when you type in and get results back from the database, then the <ul> gets rendered.



The above functionality is done, however, what I want to accomplish now is that when I'm done typing (because I'm satisfied with the results I see) and I hit tab, then the first item on the results list (precisely a <a> within the <li>) gets focused, and then if I continue to hit tab the next item on the last will focus and so on until it reaches the final item.



So, essentially the focus action could come from either hitting tab on the input or, from the current list item (if it has already been focused).



I've been thinking about the cleanest approach to get this to work. I thought perhaps using ref via createRef and forwardRed could be a good idea, but honestly I can't wrap my head around it for the time being so I thought I'd reach out for help.



This is essentially what it looks like (everything is working as intended, I cut out pretty much all the logic to strip it down to the basics and focus on the main issue here, which is, well, focus...).



Parent Component:



class Parent extends React.Component {
componentDidMount() {}

handleInternalKeyPress = (e) => {
if (e.key === 'Tab') {
e.preventDefault()
// do something?
}
}

render() {
return (
<section>
<section>
<DropdownInput
handleTextChange={this.props.handleTextChange}
handleKeyDown={this.handleInternalKeyPress}
/>
<DropdownResults
results={this.props.results}
handleKeyDown={this.handleInternalKeyPress}
/>
</section>
</section>
)
}
}


Input Component:



const DropdownInput = props => (
<Input
onChange={e => props.handleTextChange(e)}
onKeyDown={e => props.handleKeyDown(e)}
type="text"
/>
)


Results component (<ul>):



// Maybe this should be a React.forwardRef() instead of
// an arrow function, but I'm not sure if this is the
// best/most elegant approach
const DropdownResults = props => (
<ul>
{props.results.map((result, i) => (
<li key={result.resultIdKey}>
<a
// perhaps a ref should go in here?
onKeyDown={e => props.handleKeyDown(e)}
role="link"
tabIndex={i}
>
{result.resultTitleDisplayKey}
</a>
</li>
))}
</ul>
)


Again, the compoenents are quite a bit more complex than this, but this is the basic idea of how they work.



It would also be ideal to get a hold of the focused item to set custom styles to it, for instance.



I've been giving it some thought but this one has really got me, particularly because I want to adhere to best/latest React practices so any help that can be provided will be much appreciated!










share|improve this question





























    1

















    EDIT: While Sung Kim's answer is correct for the original scenario, I forgot to add that this behaviour (of selecting the next item from the list) can be toggled by some other key, for instance ArrowDown, in which case the tabIndex would not be of much help initially at least.



    `````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````



    I'm trying to work on a dropdown component that has two separate (sibling) functional components. The first one is a regular <input> that will take in a value.
    The second one is a <ul> that will display the results.



    The flow is that initially only the <input> is displayed, when you type in and get results back from the database, then the <ul> gets rendered.



    The above functionality is done, however, what I want to accomplish now is that when I'm done typing (because I'm satisfied with the results I see) and I hit tab, then the first item on the results list (precisely a <a> within the <li>) gets focused, and then if I continue to hit tab the next item on the last will focus and so on until it reaches the final item.



    So, essentially the focus action could come from either hitting tab on the input or, from the current list item (if it has already been focused).



    I've been thinking about the cleanest approach to get this to work. I thought perhaps using ref via createRef and forwardRed could be a good idea, but honestly I can't wrap my head around it for the time being so I thought I'd reach out for help.



    This is essentially what it looks like (everything is working as intended, I cut out pretty much all the logic to strip it down to the basics and focus on the main issue here, which is, well, focus...).



    Parent Component:



    class Parent extends React.Component {
    componentDidMount() {}

    handleInternalKeyPress = (e) => {
    if (e.key === 'Tab') {
    e.preventDefault()
    // do something?
    }
    }

    render() {
    return (
    <section>
    <section>
    <DropdownInput
    handleTextChange={this.props.handleTextChange}
    handleKeyDown={this.handleInternalKeyPress}
    />
    <DropdownResults
    results={this.props.results}
    handleKeyDown={this.handleInternalKeyPress}
    />
    </section>
    </section>
    )
    }
    }


    Input Component:



    const DropdownInput = props => (
    <Input
    onChange={e => props.handleTextChange(e)}
    onKeyDown={e => props.handleKeyDown(e)}
    type="text"
    />
    )


    Results component (<ul>):



    // Maybe this should be a React.forwardRef() instead of
    // an arrow function, but I'm not sure if this is the
    // best/most elegant approach
    const DropdownResults = props => (
    <ul>
    {props.results.map((result, i) => (
    <li key={result.resultIdKey}>
    <a
    // perhaps a ref should go in here?
    onKeyDown={e => props.handleKeyDown(e)}
    role="link"
    tabIndex={i}
    >
    {result.resultTitleDisplayKey}
    </a>
    </li>
    ))}
    </ul>
    )


    Again, the compoenents are quite a bit more complex than this, but this is the basic idea of how they work.



    It would also be ideal to get a hold of the focused item to set custom styles to it, for instance.



    I've been giving it some thought but this one has really got me, particularly because I want to adhere to best/latest React practices so any help that can be provided will be much appreciated!










    share|improve this question



























      1












      1








      1










      EDIT: While Sung Kim's answer is correct for the original scenario, I forgot to add that this behaviour (of selecting the next item from the list) can be toggled by some other key, for instance ArrowDown, in which case the tabIndex would not be of much help initially at least.



      `````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````



      I'm trying to work on a dropdown component that has two separate (sibling) functional components. The first one is a regular <input> that will take in a value.
      The second one is a <ul> that will display the results.



      The flow is that initially only the <input> is displayed, when you type in and get results back from the database, then the <ul> gets rendered.



      The above functionality is done, however, what I want to accomplish now is that when I'm done typing (because I'm satisfied with the results I see) and I hit tab, then the first item on the results list (precisely a <a> within the <li>) gets focused, and then if I continue to hit tab the next item on the last will focus and so on until it reaches the final item.



      So, essentially the focus action could come from either hitting tab on the input or, from the current list item (if it has already been focused).



      I've been thinking about the cleanest approach to get this to work. I thought perhaps using ref via createRef and forwardRed could be a good idea, but honestly I can't wrap my head around it for the time being so I thought I'd reach out for help.



      This is essentially what it looks like (everything is working as intended, I cut out pretty much all the logic to strip it down to the basics and focus on the main issue here, which is, well, focus...).



      Parent Component:



      class Parent extends React.Component {
      componentDidMount() {}

      handleInternalKeyPress = (e) => {
      if (e.key === 'Tab') {
      e.preventDefault()
      // do something?
      }
      }

      render() {
      return (
      <section>
      <section>
      <DropdownInput
      handleTextChange={this.props.handleTextChange}
      handleKeyDown={this.handleInternalKeyPress}
      />
      <DropdownResults
      results={this.props.results}
      handleKeyDown={this.handleInternalKeyPress}
      />
      </section>
      </section>
      )
      }
      }


      Input Component:



      const DropdownInput = props => (
      <Input
      onChange={e => props.handleTextChange(e)}
      onKeyDown={e => props.handleKeyDown(e)}
      type="text"
      />
      )


      Results component (<ul>):



      // Maybe this should be a React.forwardRef() instead of
      // an arrow function, but I'm not sure if this is the
      // best/most elegant approach
      const DropdownResults = props => (
      <ul>
      {props.results.map((result, i) => (
      <li key={result.resultIdKey}>
      <a
      // perhaps a ref should go in here?
      onKeyDown={e => props.handleKeyDown(e)}
      role="link"
      tabIndex={i}
      >
      {result.resultTitleDisplayKey}
      </a>
      </li>
      ))}
      </ul>
      )


      Again, the compoenents are quite a bit more complex than this, but this is the basic idea of how they work.



      It would also be ideal to get a hold of the focused item to set custom styles to it, for instance.



      I've been giving it some thought but this one has really got me, particularly because I want to adhere to best/latest React practices so any help that can be provided will be much appreciated!










      share|improve this question


















      EDIT: While Sung Kim's answer is correct for the original scenario, I forgot to add that this behaviour (of selecting the next item from the list) can be toggled by some other key, for instance ArrowDown, in which case the tabIndex would not be of much help initially at least.



      `````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````



      I'm trying to work on a dropdown component that has two separate (sibling) functional components. The first one is a regular <input> that will take in a value.
      The second one is a <ul> that will display the results.



      The flow is that initially only the <input> is displayed, when you type in and get results back from the database, then the <ul> gets rendered.



      The above functionality is done, however, what I want to accomplish now is that when I'm done typing (because I'm satisfied with the results I see) and I hit tab, then the first item on the results list (precisely a <a> within the <li>) gets focused, and then if I continue to hit tab the next item on the last will focus and so on until it reaches the final item.



      So, essentially the focus action could come from either hitting tab on the input or, from the current list item (if it has already been focused).



      I've been thinking about the cleanest approach to get this to work. I thought perhaps using ref via createRef and forwardRed could be a good idea, but honestly I can't wrap my head around it for the time being so I thought I'd reach out for help.



      This is essentially what it looks like (everything is working as intended, I cut out pretty much all the logic to strip it down to the basics and focus on the main issue here, which is, well, focus...).



      Parent Component:



      class Parent extends React.Component {
      componentDidMount() {}

      handleInternalKeyPress = (e) => {
      if (e.key === 'Tab') {
      e.preventDefault()
      // do something?
      }
      }

      render() {
      return (
      <section>
      <section>
      <DropdownInput
      handleTextChange={this.props.handleTextChange}
      handleKeyDown={this.handleInternalKeyPress}
      />
      <DropdownResults
      results={this.props.results}
      handleKeyDown={this.handleInternalKeyPress}
      />
      </section>
      </section>
      )
      }
      }


      Input Component:



      const DropdownInput = props => (
      <Input
      onChange={e => props.handleTextChange(e)}
      onKeyDown={e => props.handleKeyDown(e)}
      type="text"
      />
      )


      Results component (<ul>):



      // Maybe this should be a React.forwardRef() instead of
      // an arrow function, but I'm not sure if this is the
      // best/most elegant approach
      const DropdownResults = props => (
      <ul>
      {props.results.map((result, i) => (
      <li key={result.resultIdKey}>
      <a
      // perhaps a ref should go in here?
      onKeyDown={e => props.handleKeyDown(e)}
      role="link"
      tabIndex={i}
      >
      {result.resultTitleDisplayKey}
      </a>
      </li>
      ))}
      </ul>
      )


      Again, the compoenents are quite a bit more complex than this, but this is the basic idea of how they work.



      It would also be ideal to get a hold of the focused item to set custom styles to it, for instance.



      I've been giving it some thought but this one has really got me, particularly because I want to adhere to best/latest React practices so any help that can be provided will be much appreciated!







      reactjs






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 15 '18 at 22:02







      deathandtaxes

















      asked Nov 15 '18 at 20:35









      deathandtaxesdeathandtaxes

      8618




      8618
























          1 Answer
          1






          active

          oldest

          votes


















          1
















          I've never used tabIndex but played around after reading some articles.



          It looked like setting the tabIndex={0} worked instead of increasing it using i.



          const DropdownResults = props => (
          <ul>
          {props.results.map((result, i) => (
          <li key={result.resultIdKey}>
          <a
          // perhaps a ref should go in here?
          onKeyDown={e => props.handleKeyDown(e)}
          role="link"
          tabIndex={0}
          >
          {result.resultTitleDisplayKey}
          </a>
          </li>
          ))}
          </ul>
          );


          demo



          For some reason Google documentation (Using tabindex) says using tabIndex greater than 0 is an anti-pattern without much explanation (as well as this older blog post, which doesn't explain why not either)



          even though MDN documentation doesn't say anything about using tabIndex greater than 0 being an anti-pattern.



          But for now setting all values of tabIndex=0 seems to work.



          You can fork the code.
          Edit 002pz9kp20






          share|improve this answer
























          • Hey, thanks so much for the quick reply! Would you mind looking at the edit on the original post? This absolutely solved the native tab behaviour, but how about using other keys to tab, such as arrowdown. Thanks!

            – deathandtaxes
            Nov 15 '18 at 22:03






          • 1





            @deathandtaxes Do you mean, you want to be able to move to different items using "arrow keys" as an alternative? (That's how I understood the updated question)...

            – Sung M. Kim
            Nov 15 '18 at 22:14






          • 1





            Yes, exactly. I don't think this would be too complicated once the first item on the list has been selected. However I'm stuck on how to get that first item focused when you finished typing on the input and hit "ArrowDown" (from the arrow keys).

            – deathandtaxes
            Nov 15 '18 at 22:17













          • @deathandtaxes I've updated the Sandbox using forwardRef to pass the list of refs down to the children so you can select using both tabs & arrow keys. It looks quite ugly by the way even though it works... It'd require heavy refactors.

            – Sung M. Kim
            Nov 16 '18 at 3:54













          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53327522%2freact-focus-items-list-in-child-component-after-action-from-a-different-child-co%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1
















          I've never used tabIndex but played around after reading some articles.



          It looked like setting the tabIndex={0} worked instead of increasing it using i.



          const DropdownResults = props => (
          <ul>
          {props.results.map((result, i) => (
          <li key={result.resultIdKey}>
          <a
          // perhaps a ref should go in here?
          onKeyDown={e => props.handleKeyDown(e)}
          role="link"
          tabIndex={0}
          >
          {result.resultTitleDisplayKey}
          </a>
          </li>
          ))}
          </ul>
          );


          demo



          For some reason Google documentation (Using tabindex) says using tabIndex greater than 0 is an anti-pattern without much explanation (as well as this older blog post, which doesn't explain why not either)



          even though MDN documentation doesn't say anything about using tabIndex greater than 0 being an anti-pattern.



          But for now setting all values of tabIndex=0 seems to work.



          You can fork the code.
          Edit 002pz9kp20






          share|improve this answer
























          • Hey, thanks so much for the quick reply! Would you mind looking at the edit on the original post? This absolutely solved the native tab behaviour, but how about using other keys to tab, such as arrowdown. Thanks!

            – deathandtaxes
            Nov 15 '18 at 22:03






          • 1





            @deathandtaxes Do you mean, you want to be able to move to different items using "arrow keys" as an alternative? (That's how I understood the updated question)...

            – Sung M. Kim
            Nov 15 '18 at 22:14






          • 1





            Yes, exactly. I don't think this would be too complicated once the first item on the list has been selected. However I'm stuck on how to get that first item focused when you finished typing on the input and hit "ArrowDown" (from the arrow keys).

            – deathandtaxes
            Nov 15 '18 at 22:17













          • @deathandtaxes I've updated the Sandbox using forwardRef to pass the list of refs down to the children so you can select using both tabs & arrow keys. It looks quite ugly by the way even though it works... It'd require heavy refactors.

            – Sung M. Kim
            Nov 16 '18 at 3:54


















          1
















          I've never used tabIndex but played around after reading some articles.



          It looked like setting the tabIndex={0} worked instead of increasing it using i.



          const DropdownResults = props => (
          <ul>
          {props.results.map((result, i) => (
          <li key={result.resultIdKey}>
          <a
          // perhaps a ref should go in here?
          onKeyDown={e => props.handleKeyDown(e)}
          role="link"
          tabIndex={0}
          >
          {result.resultTitleDisplayKey}
          </a>
          </li>
          ))}
          </ul>
          );


          demo



          For some reason Google documentation (Using tabindex) says using tabIndex greater than 0 is an anti-pattern without much explanation (as well as this older blog post, which doesn't explain why not either)



          even though MDN documentation doesn't say anything about using tabIndex greater than 0 being an anti-pattern.



          But for now setting all values of tabIndex=0 seems to work.



          You can fork the code.
          Edit 002pz9kp20






          share|improve this answer
























          • Hey, thanks so much for the quick reply! Would you mind looking at the edit on the original post? This absolutely solved the native tab behaviour, but how about using other keys to tab, such as arrowdown. Thanks!

            – deathandtaxes
            Nov 15 '18 at 22:03






          • 1





            @deathandtaxes Do you mean, you want to be able to move to different items using "arrow keys" as an alternative? (That's how I understood the updated question)...

            – Sung M. Kim
            Nov 15 '18 at 22:14






          • 1





            Yes, exactly. I don't think this would be too complicated once the first item on the list has been selected. However I'm stuck on how to get that first item focused when you finished typing on the input and hit "ArrowDown" (from the arrow keys).

            – deathandtaxes
            Nov 15 '18 at 22:17













          • @deathandtaxes I've updated the Sandbox using forwardRef to pass the list of refs down to the children so you can select using both tabs & arrow keys. It looks quite ugly by the way even though it works... It'd require heavy refactors.

            – Sung M. Kim
            Nov 16 '18 at 3:54
















          1












          1








          1









          I've never used tabIndex but played around after reading some articles.



          It looked like setting the tabIndex={0} worked instead of increasing it using i.



          const DropdownResults = props => (
          <ul>
          {props.results.map((result, i) => (
          <li key={result.resultIdKey}>
          <a
          // perhaps a ref should go in here?
          onKeyDown={e => props.handleKeyDown(e)}
          role="link"
          tabIndex={0}
          >
          {result.resultTitleDisplayKey}
          </a>
          </li>
          ))}
          </ul>
          );


          demo



          For some reason Google documentation (Using tabindex) says using tabIndex greater than 0 is an anti-pattern without much explanation (as well as this older blog post, which doesn't explain why not either)



          even though MDN documentation doesn't say anything about using tabIndex greater than 0 being an anti-pattern.



          But for now setting all values of tabIndex=0 seems to work.



          You can fork the code.
          Edit 002pz9kp20






          share|improve this answer















          I've never used tabIndex but played around after reading some articles.



          It looked like setting the tabIndex={0} worked instead of increasing it using i.



          const DropdownResults = props => (
          <ul>
          {props.results.map((result, i) => (
          <li key={result.resultIdKey}>
          <a
          // perhaps a ref should go in here?
          onKeyDown={e => props.handleKeyDown(e)}
          role="link"
          tabIndex={0}
          >
          {result.resultTitleDisplayKey}
          </a>
          </li>
          ))}
          </ul>
          );


          demo



          For some reason Google documentation (Using tabindex) says using tabIndex greater than 0 is an anti-pattern without much explanation (as well as this older blog post, which doesn't explain why not either)



          even though MDN documentation doesn't say anything about using tabIndex greater than 0 being an anti-pattern.



          But for now setting all values of tabIndex=0 seems to work.



          You can fork the code.
          Edit 002pz9kp20







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 15 '18 at 21:13









          Sung M. KimSung M. Kim

          17.8k33112163




          17.8k33112163













          • Hey, thanks so much for the quick reply! Would you mind looking at the edit on the original post? This absolutely solved the native tab behaviour, but how about using other keys to tab, such as arrowdown. Thanks!

            – deathandtaxes
            Nov 15 '18 at 22:03






          • 1





            @deathandtaxes Do you mean, you want to be able to move to different items using "arrow keys" as an alternative? (That's how I understood the updated question)...

            – Sung M. Kim
            Nov 15 '18 at 22:14






          • 1





            Yes, exactly. I don't think this would be too complicated once the first item on the list has been selected. However I'm stuck on how to get that first item focused when you finished typing on the input and hit "ArrowDown" (from the arrow keys).

            – deathandtaxes
            Nov 15 '18 at 22:17













          • @deathandtaxes I've updated the Sandbox using forwardRef to pass the list of refs down to the children so you can select using both tabs & arrow keys. It looks quite ugly by the way even though it works... It'd require heavy refactors.

            – Sung M. Kim
            Nov 16 '18 at 3:54





















          • Hey, thanks so much for the quick reply! Would you mind looking at the edit on the original post? This absolutely solved the native tab behaviour, but how about using other keys to tab, such as arrowdown. Thanks!

            – deathandtaxes
            Nov 15 '18 at 22:03






          • 1





            @deathandtaxes Do you mean, you want to be able to move to different items using "arrow keys" as an alternative? (That's how I understood the updated question)...

            – Sung M. Kim
            Nov 15 '18 at 22:14






          • 1





            Yes, exactly. I don't think this would be too complicated once the first item on the list has been selected. However I'm stuck on how to get that first item focused when you finished typing on the input and hit "ArrowDown" (from the arrow keys).

            – deathandtaxes
            Nov 15 '18 at 22:17













          • @deathandtaxes I've updated the Sandbox using forwardRef to pass the list of refs down to the children so you can select using both tabs & arrow keys. It looks quite ugly by the way even though it works... It'd require heavy refactors.

            – Sung M. Kim
            Nov 16 '18 at 3:54



















          Hey, thanks so much for the quick reply! Would you mind looking at the edit on the original post? This absolutely solved the native tab behaviour, but how about using other keys to tab, such as arrowdown. Thanks!

          – deathandtaxes
          Nov 15 '18 at 22:03





          Hey, thanks so much for the quick reply! Would you mind looking at the edit on the original post? This absolutely solved the native tab behaviour, but how about using other keys to tab, such as arrowdown. Thanks!

          – deathandtaxes
          Nov 15 '18 at 22:03




          1




          1





          @deathandtaxes Do you mean, you want to be able to move to different items using "arrow keys" as an alternative? (That's how I understood the updated question)...

          – Sung M. Kim
          Nov 15 '18 at 22:14





          @deathandtaxes Do you mean, you want to be able to move to different items using "arrow keys" as an alternative? (That's how I understood the updated question)...

          – Sung M. Kim
          Nov 15 '18 at 22:14




          1




          1





          Yes, exactly. I don't think this would be too complicated once the first item on the list has been selected. However I'm stuck on how to get that first item focused when you finished typing on the input and hit "ArrowDown" (from the arrow keys).

          – deathandtaxes
          Nov 15 '18 at 22:17







          Yes, exactly. I don't think this would be too complicated once the first item on the list has been selected. However I'm stuck on how to get that first item focused when you finished typing on the input and hit "ArrowDown" (from the arrow keys).

          – deathandtaxes
          Nov 15 '18 at 22:17















          @deathandtaxes I've updated the Sandbox using forwardRef to pass the list of refs down to the children so you can select using both tabs & arrow keys. It looks quite ugly by the way even though it works... It'd require heavy refactors.

          – Sung M. Kim
          Nov 16 '18 at 3:54







          @deathandtaxes I've updated the Sandbox using forwardRef to pass the list of refs down to the children so you can select using both tabs & arrow keys. It looks quite ugly by the way even though it works... It'd require heavy refactors.

          – Sung M. Kim
          Nov 16 '18 at 3:54






















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53327522%2freact-focus-items-list-in-child-component-after-action-from-a-different-child-co%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Florida Star v. B. J. F.

          Danny Elfman

          Lugert, Oklahoma