Hello,
I am experiencing an issue with WebPart titles in SharePoint Online. Specifically:
When I add WebParts to a SharePoint page using the Microsoft Graph API, everything works as expected initially.
However, when the page is viewed in desktop mode, the WebPart titles do not appear. Upon inspecting the HTML, I noticed that the <span>
element intended to contain the title is generated but remains empty:
<span role="heading" aria-level="2" id="CaptionElementView" data-automation-id="webPartTitleReadMode" style="cursor: text;"></span>
When the same page is viewed on mobile devices, or in a browser using mobile emulation, the WebPart titles are correctly populated.
The corresponding HTML in mobile mode is as follows:
<span role="heading" aria-level="2" id="CaptionElementView" data-automation-id="webPartTitleReadMode" style="cursor: text;">Document Tracker</span>
I believe this is a bug in the rendering of WebParts in desktop mode. It seems that the title information is either not passed correctly or not rendered in the desktop view.
Steps to Reproduce
- Use Microsoft Graph API to add a WebPart (e.g., a List WebPart) to a SharePoint page.
here is the C# code i use:
var listWebPartRequest = new Microsoft.Graph.Beta.Models.StandardWebPart {
OdataType = "#microsoft.graph.standardWebPart",
WebPartType = "f92bf067-bc19-489e-a556-7fe95f508720",
Data = new Microsoft.Graph.Beta.Models.WebPartData {
Title = "Document Tracker",
Properties = new Microsoft.Graph.Beta.Models.Json {
AdditionalData = new Dictionary<string, object>
{
{ "selectedListId", documentTrackerList.Id },
{ "selectedListUrl", relativeSiteUrl + "/Document Tracker" },
{ "webRelativeListUrl", "/Lists/Document Tracker" },
{ "webpartHeightKey", "4" }
}
},
DataVersion = "1.0"
}
};
var listWebPartResult = await betaClient.Sites[projectSite.Id].Pages[homePage.Id].GraphSitePage.CanvasLayout.HorizontalSections["3"].Columns["1"].Webparts.PostAsync(listWebPartRequest);
- Open the page in a desktop browser and observe that the WebPart title is missing.
- Open the same page on a mobile device or use mobile emulation in the browser. The title will be correctly displayed.
Am I doing something wrong?