Skip to content

[no-node-access] allow using "blur" on DOM elements in addition to "focus" #1030

Closed
@danielrentz

Description

@danielrentz

What rule do you want to change?

no-node-access

Does this change cause the rule to produce more or fewer warnings?

Fewer warnings

How will the change be implemented?

The rule should allow calling element.blur(). I have tests that check behavior of some elements after receiving and losing focus. Being able to call "blur" would prevent having to add another helper element just for moving focus somewhere else. (btw, document.body.focus() does not seem to work).

Example code

it("should trigger onBlur handler", () => {
    const onBlur = vi.fn();
    render(<CheckBox onBlur={onBlur} />);
    const input = screen.getByRole("checkbox");
    input.focus();
    expect(onBlur).not.toHaveBeenCalled();
    input.blur();
    expect(onBlur).toHaveBeenCalledOnce();
});

How does the current rule affect the code?

triggers on input.blur()

How will the new rule affect the code?

allows input.blur()

Anything else?

No response

Do you want to submit a pull request to change the rule?

No

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingreleased

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions