DocumentCard is using onClick handler to open URL.
Bug Report
- Package version(s): all
- Browser and OS versions: all
Priorities and help requested (not applicable if asking question):
Are you willing to submit a PR to fix? No
Requested priority: Normal
Describe the issue:
DocumentCard is using onClick event to open a URL. It is breaking in place navigation, accessibility, right-click context menu and a lot of stuff.
Expected behavior:
Render the URL as a <a href='xxx'> tag.
@mikewheaton
I created a PR for this but I don't think it's as simple as rendering an anchor tag due to the HTML spec and there already being anchors inside this element.
Hi, @hross
It is not only to make it accessible. We find this issue because our in-place navigation (react-router) needs <a> tag for the magic. If it is JavaScript code to change window.location.href directly, it is not possible to get in-place navigation.
I don't think my PR is 100% ideal in the case you mention @lijunle but I don't think you will be able to directly implement in that case due to the HTML spec. You could work around the problem by implementing your own click handler (instead of passing a URL) and firing a hidden anchor tag or similar if you need to, so I think it is still supportable in that instance.
Hi, @hross
I checked the document for <a> tag. It is allowing to contain the flow content. The <div> tag is one of flow content category.
That means, I think it is fine to wrap the whole DocumentCard component inside a <a> tag. However, I could step back and ask, why Fabric-React is going to integrate the click logic inside the DocumentCard component. Its parent is easy to control the logic correctly.
Note that you cannot put <a>s inside other <a>s, which is an issue because the DocumentCard can contain other links. Inner links should be <a>s, but the outside container should be a <div> and it will unfortunately just have to manage middle clicks manually.
@lijunle I am going to close this issue since there is a work around as @phkuo explained more elegantly than I did, the HTML spec doesn't allow for anchor tags inside of anchor tags :).