sp-dev-docs icon indicating copy to clipboard operation
sp-dev-docs copied to clipboard

List web part does not respect target attribute

Open RowanAdvisors opened this issue 6 years ago • 5 comments

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

  1. Create a new list
  2. Add a list item (content is not important)
  3. Apply the JSON formatting provided below
  4. 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.

RowanAdvisors avatar Jun 10 '20 22:06 RowanAdvisors

Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.

msft-github-bot avatar Jun 10 '20 22:06 msft-github-bot

An update on this would be ideal as I'd rather not build a custom web part just to fix this.

RowanAdvisors avatar Jun 15 '20 16:06 RowanAdvisors

@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.

shre-verse avatar Jun 19 '20 06:06 shre-verse

@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.

shre-verse avatar Jun 22 '20 09:06 shre-verse

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

msft-github-bot avatar Jun 29 '20 12:06 msft-github-bot