question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support "editable" on TextInput

See original GitHub issue

Describe the Feature

TextInput component from react-native has its own handling of being disabled/editable. It’s not using responder system like Views, Texts and thus Touchables, so the logic we have already fails to catch it.

We should consider adding custom handling specific to native TextInput component, since it was working with @testing-library/react-native before v7.

Possible Implementations

Will likely involve detecting TextInput and verify if it’s editable or not.

Test that fails with current implementation:

test('should not fire on disabled TextInput', () => {
  const handleChangeText = jest.fn();

  const screen = render(
    <TextInput onChangeText={handleChangeText} editable={false}>
      <Text>Trigger</Text>
    </TextInput>
  );

  fireEvent.changeText(screen.getByText('Trigger'), 'Trigger');
  expect(handleChangeText).not.toHaveBeenCalled();
});

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:4
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
douglasjuniorcommented, Aug 26, 2022

fireEvent(textInput, 'focus') still working when editable={false} 😢

I’m using version 11.0.0.

    const handleFocus = jest.fn();

    const result = render(
      <TextInput
        testID="my-input"
        onFocus={handleFocus}
        editable={false}
      />,
    );

    const rnTextInput = result.getByTestId('my-input');

    act(() => {
      fireEvent(rnTextInput, 'focus');
      // or fireEvent(rnTextInput, 'click');
      // or fireEvent.press(rnTextInput);
    });

    expect(handleFocus).not.toBeCalled();

Result:

image

1reaction
thymikeecommented, Aug 20, 2020

@pitpitpat go for it!

Read more comments on GitHub >

github_iconTop Results From Across the Web

TextInput - React Native
A foundational component for inputting text into the app via a keyboard. Props provide configurability for several features, such as auto- ...
Read more >
Change TextInput editable attribute when I press a button
I would like to change all my TextInput's editable value to editable when i press on the button "Editer". I tried some things...
Read more >
ARIA: textbox role - Accessibility - MDN Web Docs
The textbox role is used to identify an element that allows the input ... HTML contenteditable attribute ensures the text node is editable....
Read more >
Editing inputs - IBM
Edit and configure the inputs in your service. An input is automatically populated in your service for each variable in the workflow definition...
Read more >
Textbox in Edit form keep text input by user
I have create a editable form that select item from gallery. I am wondering, one textbox name: "Note" keep text that user input...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found