Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Accessibility] Capture focus via ref for RadioButtonGroup #7070

Open
ShimiSun opened this issue Dec 15, 2023 · 0 comments
Open

[Accessibility] Capture focus via ref for RadioButtonGroup #7070

ShimiSun opened this issue Dec 15, 2023 · 0 comments
Labels
accessibility WCAG support bug issue that does not match design or documentation and requires code changes to address

Comments

@ShimiSun
Copy link
Member

ShimiSun commented Dec 15, 2023

Expected Behavior

The RadioButtonGroup should be capable of capturing focus on the initial input radio element when targeted using ref, mirroring the behavior observed during keyboard navigation.

Actual Behavior

When employing react-hook-form or any form management tool to set focus on a specific input with an error, the RadioButtonGroup (RBG) currently lacks focusability through ref. As RBG is a Box without a tabIndex, it cannot be focused. Grommet appropriately handles a comparable scenario for keyboard navigation focus in RBG by directing focus to the first radio element. Similar behavior is expected when managing focus via ref for RBG.

URL, screen shot, or Codepen exhibiting the issue

A POC of the concept #7044
Story example

import React, { useEffect, useState } from 'react';

import { Box, RadioButtonGroup } from 'grommet';

export const myFocus = () => {
  const [value, setValue] = useState({ value: '' });

  const input = React.useRef();
  // This logic will trigger a focus on RBG when the page loads. You can notice that the focus is never set.
  useEffect(() => {
    setTimeout(() => {
      input.current?.focus();
      console.log('here', input.current);
    }, 500);
  }, []);

  const postMethods = [
    { label: 'FTP', value: 'FTP' },
    {
      label: 'File System',
      value: 'FileSystem',
    },
    {
      label: 'FTP & File System',
      value: 'FTPCopy',
    },
  ];

  // In this example there is no keyboard access to the RBG component
  // The myFocus should fix the initial focus
  return (
    <Box align="center" pad="large">
      <RadioButtonGroup
        ref={input}
        name="radio"
        options={postMethods}
        value={value}
        onChange={(event) => setValue(event.value)}
      />
    </Box>
  );
};
export default {
  title: 'Input/RadioButtonGroup/My Focus',
};

Steps to Reproduce

  1. Put the story on storybook
  2. Notice how the focus is not set on load, although it is triggered

Your Environment

Any

  • Grommet version: latest
  • Browser Name and version: Chrome 119
  • Operating System and version (desktop or mobile): Mac - any
@jcfilben jcfilben added bug issue that does not match design or documentation and requires code changes to address accessibility WCAG support labels Dec 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accessibility WCAG support bug issue that does not match design or documentation and requires code changes to address
Projects
None yet
Development

No branches or pull requests

2 participants