Events
Microsoft 365 Community Conference
May 6, 2 PM - May 9, 12 AM
Skill up for the era of AI at the ultimate community-led Microsoft 365 event, May 6-8 in Las Vegas.
Learn moreThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Top Actions provide an alternative and more end user friendlier way to expose the different options and configuration capabilities for web parts in edit mode. You can use Top Actions to surface most common configurations from the web part property panel directly in web part toolbar, which is exposed when the page is in edit mode.
Important
Web part Top Actions were introduced in the SharePoint Framework (SPFx) v1.17 release.
To add Top Actions to a web part, you'll implement two things:
Both of these steps are accomplished by providing a configuration object of type ITopActions to the SPFx.
Tip
These instructions assume you know how to create a hello world web part.
Adding Top Actions to a web part follows a similar pattern to configuring the web part property pane.
To add Top Actions to a web part, implement the getTopActionsConfiguration()
member that returns an object of type ITopActions:
// existing imports omitted for brevity
import {
ITopActions,
ITopActionsField
} from '@microsoft/sp-top-actions';
export default class HelloWorldWebPart extends BaseClientSideWebPart<IHelloWorldWebPartProps> {
// existing web part members omitted for brevity
public getTopActionsConfiguration(): ITopActions | undefined {
return {
topActions: [],
onExecute: (actionName: string, newValue: any): void { }
};
}
}
Notice the returned object has two properties:
topActions
: this contains an array of supported Top Action controls that are rendered in the web part's toolbar when the page is in edit modeonExecute
: this handler is called when one of the Top Actions is selectedThe topActions
array is an ordered list of controls, or fields of type ITopActionsField, to render in the web part toolbar. You can choose from two types of user interface elements:
All controls must have the following properties defined:
type
: this is the type of the control - button (TopActionsFieldType.Button
) or dropdown list (`TopActionsFieldType.Dropdown)targetProperty
: this is the name of the Top Actionproperties
: properties unique to the type of Top Action controlYou can optionally specify a title
which is used as the tooltip & value for an aria-label
property, and the Boolean shouldFocus
flag to indicate if the control should be focused.
The following code defines a button Top Action control:
import {
ITopActions,
TopActionsFieldType
} from '@microsoft/sp-top-actions';
return {
topActions: [
{
targetProperty: 'button',
type: TopActionsFieldType.Button,
title: 'Button',
properties: {
text: 'Button',
icon: 'SharePointLogo'
}
}
],
onExecute: (actionName: string, newValue: any): void { }
}
The properties
for a button control are defined in the ITopActionsButtonProps interface.
The following code defines a dropdown Top Action control:
import {
ITopActions,
TopActionsFieldType
} from '@microsoft/sp-top-actions';
return {
topActions: [
{
targetProperty: 'dropdown',
type: TopActionsFieldType.Dropdown,
title: 'Dropdown',
properties: {
options: [{
key: '1',
text: 'Option 1'
}, {
key: '2',
text: 'Option 2'
}]
}
}
],
onExecute: (actionName: string, newValue: any): void { }
}
The properties
for a dropdown control are defined in the ITopActionsButtonProps interface.
The last step is to implement the handler when Top Action controls are selected. This is done by implementing the onExecute()
method on the ITopActions interface.
The onExecute()
handler passes two arguments in that you can handle:
actionName
: maps to the targetProperty
of the Top Action control that triggered this handler to be calledupdatedValue
: when the Top Action is of type dropdown, this is the key
property of the selected dropdown option; otherwise when the Top Action is of type button, the value of this property is true
public getTopActionsConfiguration(): ITopActions | undefined {
return {
topActions: [{
type: TopActionsFieldType.Button,
title: 'Button',
targetProperty: 'button',
properties: {
text: 'Button',
icon: 'SharePointLogo'
}
}, {
type: TopActionsFieldType.Dropdown,
title: 'Dropdown',
targetProperty: 'dropdown',
properties: {
options: [{
key: '1',
text: 'Option 1'
}, {
key: '2',
text: 'Option 2'
}]
}
}],
onExecute(actionName, updatedValue) {
console.log('onExecute', actionName, updatedValue);
}
}
}
Similar to the different types of SPFx extensions, Top Actions must be tested in a live SharePoint modern page. They won't render on the SharePoint hosted workbench.
Events
Microsoft 365 Community Conference
May 6, 2 PM - May 9, 12 AM
Skill up for the era of AI at the ultimate community-led Microsoft 365 event, May 6-8 in Las Vegas.
Learn moreTraining
Module
Enable SharePoint Framework web part configuration with property panes - Training
Learn how to enable web part configurations with property panes in the SharePoint Framework.
Certification
Microsoft Certified: Power Platform Developer Associate - Certifications
Demonstrate how to simplify, automate, and transform business tasks and processes using Microsoft Power Platform Developer.
Documentation
Determine the rendered web part width
Learn how to determine the rendered width of a web part and handle when the web part is resized.
Overview of the isolated web parts capability in the SharePoint Framework
Using single part app pages in SharePoint Online
Using single part app pages in SharePoint Online