Skip to content

Focus ring on textfield is re-enabled after re-draw/re-mount #2954

@ospfranco

Description

@ospfranco

Environment

npm ls react-native-macos: 0.87.1

Using new arch

Steps to reproduce the bug

  1. Create a TextField with enableFocusRing=false
  2. Field is correctly displayed without a native macOS focus ring
  3. After some time. I've not been able to pin point why/how. The focus ring appears again.

Expected Behavior

Focus ring remains off, all the time. It seems the current code only calls setFocusRingType(...) when the prop changes. If AppKit or an internal control resets that later, React never reapplies it. I’m checking whether overriding the native getter is the safest fix for the controls used here.

Actual Behavior

No response

Reproducible Demo

No response

Additional context

This is probably not the patch you want, but AI fixed this for me with the following patches:

// Libraries/Text/TextInput/Singleline/RCTUITextField.mm
- (NSFocusRingType)focusRingType
{
  return _enableFocusRing ? NSFocusRingTypeExterior : NSFocusRingTypeNone;
}

// and on setEnableFocusRing
- (void)setEnableFocusRing:(BOOL)enableFocusRing {
  if (_enableFocusRing != enableFocusRing) {
    _enableFocusRing = enableFocusRing;
  }

  [super setFocusRingType:self.focusRingType];
  [self setKeyboardFocusRingNeedsDisplayInRect:self.bounds];
}

and

// On React/Base/macos/RCTUIKit.m
// seems changes are replicated from RCTUITextField.mm
- (NSFocusRingType)focusRingType
{
  return _enableFocusRing ? NSFocusRingTypeExterior : NSFocusRingTypeNone;
}

- (void)setEnableFocusRing:(BOOL)enableFocusRing {
  if (_enableFocusRing != enableFocusRing) {
    _enableFocusRing = enableFocusRing;
  }

  [super setFocusRingType:self.focusRingType];
  [self setKeyboardFocusRingNeedsDisplayInRect:self.bounds];
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions