List web part does not respect target attribute
Category
- [x] Bug
Describe the bug
The OoTB List web part does not respect the target setting for anchor (a) elements in the JSON formatting for the view if the href is an internal SharePoint link. Instead the link is opened in the same tab/window.
Steps to reproduce
- Create a new list
- Add a list item (content is not important)
- Apply the JSON formatting provided below
- Add the List web part to a page and select the formatted view
JSON Formatting (simplified from source):
{
"schema": "https://developer.microsoft.com/json-schemas/sp/view-formatting.schema.json",
"hideSelection": false,
"hideColumnHeader": true,
"rowFormatter": {
"elmType": "div",
"attributes": {
"class":"sp-row-listPadding"
},
"style":{
"padding":"0.9em"
},
"children": [
{
"elmType": "div",
"attributes": {
"class":"sp-cell"
},
"style": {
"text-align": "left"
},
"children": [
{
"elmType": "a",
"attributes": {
"class": "sp-cell",
"href": "/",
"target":"_blank"
},
"style": {
"padding-left":"1em"
},
"txtContent": "Root Site"
}
]
}
]
}
}
Expected behavior
Clicking on the generated link opens the link in a new tab since the target is set to _blank.
Environment details (development & target environment)
SharePoint Online: Targeted release for everyone Browser: Chromium Edge/Chrome
Additional context
Attempting to have a formatted list view render links to open documents. The list items have a URL field that stores the document's full open URL.
Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.
An update on this would be ideal as I'd rather not build a custom web part just to fix this.
@RowanAdvisors Thanks for reporting this.
SPFX webparts by default open hyperlinks in the same tab. The behavior is documented here. We are taking a fix to provide a way to configure the same using the formatters too.
I will update the thread, once the fix is rolled out.
@RowanAdvisors Happy to share that we have fixed the issue. In the upcoming update, the anchor tags in custom formatter inside a List webpart will open in a new tab by default, if target _blank is specified. Hope that helps.
Issues that have been closed & had no follow-up activity for at least 7 days are automatically locked. Please refer to our wiki for more details, including how to remediate this action if you feel this was done prematurely or in error: Issue List: Our approach to locked issues