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

react/jsx-no-target-blank not working as expected on conditionals #3462

Closed
akulsr0 opened this issue Oct 14, 2022 · 1 comment · Fixed by #3464
Closed

react/jsx-no-target-blank not working as expected on conditionals #3462

akulsr0 opened this issue Oct 14, 2022 · 1 comment · Fixed by #3464

Comments

@akulsr0
Copy link
Contributor

akulsr0 commented Oct 14, 2022

Code

const openInNewTab = true; // could be true or false

export default function App() {
  return (
    <a
      href="https://google.com"
      target={openInNewTab ? "_blank" : "self"}
      rel={openInNewTab ? "noreferrer" : undefined}
    >
      Open Google
    </a>
  );
}

Currently what's happening

If I pass target='_blank' based on some condition as shown in the above snippet, and pass rel='noreferrer' on same condition. It is still showing me warning/error as per the config.

What should happen?

Ideally if the condition is same for both the props it should recognise it and should not give us warning/error.

Please let me know if I am missing something?

Reference:

Sample Codesandbox - https://codesandbox.io/s/mystifying-lake-l0420z?file=/src/App.js

@ljharb
Copy link
Member

ljharb commented Oct 14, 2022

I agree, this would be a good enhancement to add. This seems highly similar to #2748, in case anyone wants to tackle it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

2 participants