Description
The tab component uses an <a>
element to wrap the tab contents but prevents default navigation behavior through the use of href="javascript:void(0);"
. This doesn't play nicely with CSP policies without the unsafe-inline
directive which prevent the script from executing but also add a warning in the console.
The SLDS blueprints for the tab component seem to suggest the Javascript URL approach as well so I'm not sure whether this issue really belongs there.
A potential solution would be to prevent the default behavior of click/keydown events where they're handled within the parent tabs component.
design-system-react/components/tabs/index.jsx
Lines 252 to 298 in ecb0854
Happy to contribute if there's an agreeable fix.
It looks like there are some more examples of this. #2463 seems likely related.
Activity
garygong commentedon Apr 3, 2020
I wonder if we can just use a
<button>
instead of<a>
, or maybe a<span>
with atabIndex
.dcefram commentedon May 11, 2020
To add to this issue, latest versions of React is now throwing a warning due to the use of
javascript:void(0)
. Actual warning:I also agree with using a button instead of an anchor tag, as is recommended here.
javascript:
URLs #2514stale commentedon Jul 11, 2020
This issue has been automatically marked as stale, because it has not had recent activity. It will be closed if no further activity occurs. Maintainers are responsible for tech debt and project health. This is most likely a new components or component feature request. Please submit a pull request for or request feedback on this feature. Thank you.
jimmydief commentedon Dec 11, 2020
@garygong Can you reopen this one? I'd like to revive #2514.
interactivellama commentedon Dec 14, 2020
@jimmydief I'm cool with not following the SLDS blueprint/HTML strictly. LWC components do not.
jimmydief commentedon Dec 15, 2020
@interactivellama Mind taking a look at #2514? This seems like it would address this issue and unblock upgrading to React 16.9.0 and above for those who dislike deprecation warnings. There are some places where
<a>
=><button>
makes a lot of sense (e.g. the tab component mentioned in this issue which is unlikely to navigate to another page) but others where the correct tag is more contextual (e.g. options in a combobox menu, some of which may navigate elsewhere while others autocomplete). Seems like it might be easier to address those on a case-by-case basis.javascript:
URLs #2829jimmydief commentedon Apr 20, 2021
Fixed by #2829.