The radio button's tabIndex attribute for tab navigation is not functioning properly in React

I am currently working with 2 radio buttons and I had hoped to utilize tabIndex on each radio input. This way, users could navigate between the inputs and select values using the up and down arrow keys on their keyboards. However, it seems that this functionality isn't working as expected in my code.

<div>
        {[
          {
            id: '1',
            name: 'One',
            label: '1',
            value: false,
            defaultChecked: true,
          },
          {
            id: '2',
            name: 'Two',
            label: '2',
            value: true,
          },
        ].map(({ id, name, label, value, defaultChecked }) => (
          <div key={id} >
            <Radio
              key={id}
              id={id}
              name={name}
              value={value.toString()}
              defaultChecked={defaultChecked}
              onChange={e => console.log(e)}
              tabIndex={+id}
            >
              {label}
            </Radio>
          </div>
        ))}
      </div>

If you'd like to see a demo of this in action, you can check out the link below: https://stackblitz.com/edit/react-ts-xbcqdf

Answer №1

Your tabs seem to be functioning correctly, however, it is important to assign the same name to both checkboxes in order for them to operate as a group and allow for proper selection and deselection.

<Radio
   key={id}
   id={id}
   name="sameGroupName"  // ensure both checkboxes have the same name
   value={value.toString()}
   defaultChecked={defaultChecked}
   onChange={e => console.log(e)}
   tabIndex={+id}
   >
     {label}
</Radio>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

invalid audio element

I'm currently working on building an audio player with a visualizer feature. However, when I try to initiate the audio player by clicking on the input button, my debug console keeps showing this error message: Uncaught (in promise) DOMException: Fa ...

Attempting to update the content of a specific div element on a webpage without disrupting its current position

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>ajax div example</title> <script type="text/javascript" src="jscripts/jquery-1.6.4.min.js" ...

Guide on converting a buffer to a PDF file using front-end technologies

I utilized Puppeteer to create a buffer containing pdf data and then transmitted it to the frontend application. Below is the code snippet for the backend API: exports.getPDF = async (req, res) => { const { content } = req.query; const browser = ...

How can the reference to a promise be used in Node.js UnhandledRejection event parameters?

When an error occurs, we have options for handling it such as recording it in logs, displaying it on the page or console, and more. But what about the promise reference passed to the handler as the second parameter? process.on('unhandledRejection&apos ...

Deciphering WHERE conditions in a Node.js environment

Looking to convert the WHERE clause of a MySQL query into an expression for extracting data from a JSON file. For instance: `price`=8.95 AND `title`="The Lord price= AND of the Rings" The above example should transform into the following string after su ...

Issue with JavaScript removeAttribute for the "readonly" attribute not functioning as expected

Hi there, I'm new to JavaScript and I'm trying to remove the readonly attribute from some text input fields. My code seems to be working, but there's a strange behavior where the readonly attribute is removed for about 1 second and then it g ...

Even with the addition of a key prop, the console still indicates that the list requires a unique key

I am working with an array of objects and trying to fetch data from it. I have added key props to both the first and second div, but I am still getting a console warning saying: Warning: Each child in a list should have a unique "key" prop. const data ...

What is the best way to apply a png overlay to each img tag when hovered over?

Here is the code snippet I am working with: <div class="latest-post"> <a href="http://localhost/blaze/2011/documentaries/test-big-thumb" rel="bookmark"> <span> <img width="140" height="100" src="http:// ...

When I tap on it, the box should shift its position

Here's a conundrum for you. I have a box that I want to move 200px to the left when clicked, but I'm struggling to make it work. Can someone please lend a hand and point out where I'm going wrong? <style> .box { width: 200px; ...

Incorporating real-time camera scanning using "react-qr-reader" in your React application

Hello, I've been working on creating a web-based QR scanner using Next.js, but I'm struggling to figure out how to implement live video for scanning QR codes. import React, { Component } from "react"; import dynamic from "next/dyna ...

Obtain email addresses from a Google account

I've encountered a challenge while creating a website for a client who requested the ability for users to sign up or log in using their Google and Facebook accounts. My current hurdle involves extracting the user's email address from their Google ...

webpack - compile one TypeScript file separately (2 actions)

In summary... When my Vue files are combined with background.ts, webpack processes them to create bundled vue files along with background.js I'm unable to run the background.js script I expected background.js to only contain "console.log(' ...

Sending an Object Back from a Function

Currently, my goal is to extract an object from a function. By utilizing an Angular JS promise, I am able to successfully log the availableProviders once they have finished loading, and this information is being displayed correctly in my console. function ...

Why is the useContext array appearing empty when accessed in a function within the same context, despite being pre-populated?

I am encountering an issue with my useContext setup, where I provide all logged-in users. When the app runs initially or when users log in, the array is populated with all current users on the server, which works as intended. However, when the "user-connec ...

Determine whether a child element is missing a certain class

I am currently investigating whether a child element lacks a specific class. The elements in question are: <g id="note1"> <path id="Barline1" d="M55.837,19.278h0.249c0.11,0,0.199,0.089,0.199,0.199V40.56c0,0.11-0.089,0.199-0.199,0.199h-0.249c ...

Display the main body of the page while excluding the top and bottom sections

I have been experimenting with incorporating smooth transitions between the pages on my website using framer motion and react router. Below is a snippet of my code: <AnimatePresence initial={false} exitBeforeEnter> <Switch loc ...

Having Difficulty Modifying the CSS Styles of a Specific Class

I've been struggling with a CSS styling issue for some time now. The problem lies in targeting the class for the thumbnail preview of vue2-dropzone (which shares similar properties with dropzone.js based on documentation). Each time I upload an image, ...

Creating scalable controllers in ExpressJS

Recently diving into Node, I am venturing into the realm of creating an MVC app with ExpressJS. To mimic the structure of a well-known MVC example found on GitHub, I have organized my controllers into two main folders: main and system. My goal is to establ ...

Is there a way to create a bar chart that begins at the 0 point of the y-axis instead of starting from the base of the SVG?

Is there a way to start the bar chart from the 0 point of the y-axis instead of the very bottom of the svg? How can I achieve this? let url = "https://raw.githubusercontent.com/freeCodeCamp/ProjectReferenceData/master/GDP-data.json"; const padding = 5 ...

Determine whether a directive possesses a specific attribute

Here is my current code snippet: <my-directive></my-directive> I am trying to include a ternary operation within it like this: {{ $scope.my-option ? 'YES' : 'NO' }} Is it possible to achieve the desired result by adding ...