Skip to content

RadioGroup intercepts space key events preventing text input in nested TextField/EditableText widgets #175511

@toineheuvelmans

Description

@toineheuvelmans

Summary

In Flutter 3.35.3, the new RadioGroup widget intercepts space key events, preventing space characters from being entered in TextField or EditableText widgets nested within the RadioGroup.

Platform

  • Platform: Web
  • Flutter Version: 3.35.3 (introduced with RadioGroup widget)
  • Browser: Chrome, Firefox (likely all browsers)

Steps to Reproduce

  1. Create a RadioGroup containing Radio widgets and a TextField
  2. Run on Flutter Web
  3. Select a radio option and focus the TextField
  4. Try typing space characters
  5. Observe that spaces are ignored while other characters work fine

Expected Behavior

Space characters should be inserted into the TextField just like any other character.

Actual Behavior

Space key presses are consumed by the RadioGroup widget and never reach the TextField.

Code Sample

RadioGroup<TestOption>(
  groupValue: _selectedOption,
  onChanged: (value) => setState(() => _selectedOption = value!),
  child: Column(
    children: [
      ListTile(
        title: Text('Text Input Option'),
        leading: Radio<TestOption>(value: TestOption.textInput),
      ),
      if (_selectedOption == TestOption.textInput)
        TextField(
          // Space key input is ignored here
          decoration: InputDecoration(hintText: 'Spaces ignored...'),
        ),
    ],
  ),
)

Root Cause

The RadioGroup widget defines a space key shortcut that intercepts all space key events within its widget tree. In the Flutter source code (radio_group.dart lines 94 and 118-132), RadioGroup registers this shortcut:

const SingleActivator(LogicalKeyboardKey.space): VoidCallbackIntent(_toggleFocusedRadio),

The _toggleFocusedRadio() method:

  1. Finds the currently focused radio button
  2. If the radio isn't selected, selects it by calling onChanged(radio.radioValue)
  3. If the radio supports tristate and is already selected, deselects it by calling onChanged(null)

This shortcut mechanism consumes space key events before they can bubble down to nested TextField or EditableText widgets, preventing space characters from being entered in text inputs that are children of the RadioGroup.

Source Reference: Flutter SDK radio_group.dart at /packages/flutter/lib/src/widgets/radio_group.dart:94

Workaround

Use the deprecated individual Radio properties (groupValue, onChanged) instead of RadioGroup:

// Instead of RadioGroup, use individual Radio widgets
Radio<TestOption>(
  value: TestOption.textInput,
  groupValue: _selectedOption,  // deprecated but functional
  onChanged: (value) => setState(() => _selectedOption = value!),
)

Impact

This breaks common UI patterns where radio buttons control the visibility/behavior of text input fields, which is a standard form design pattern.

Reproduction Project

flutter_radiogroup_bug_repro.zip

Complete reproduction case can be created following the code sample above.

Test Instructions:

  1. Create a Flutter web app with the code sample
  2. Run flutter run -d chrome
  3. Select "Text Input Option" radio button
  4. Try typing spaces in the text field - they will be ignored
  5. Compare behavior outside RadioGroup - spaces work there

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work lista: text inputEntering text in a text field or keyboard related problemsfound in release: 3.35Found to occur in 3.35found in release: 3.37Found to occur in 3.37frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer versionteam-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

Type

No type

Projects

Status

Done (PR merged)

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions