Introduction
In this article, you will learn how to add slider property to SharePoint Framework Web part properties pane.
Several types of Web part properties are available, which can be added to SPFx Web part properties pane. Here, we will see how to add slider property and a basic sample to load SharePoint list content on the Web part, which is based on the slider value.
Slider property definition
The definition of Property Pane slider method is given in the links below.
Note
The property definition might be changing, since the SPFx is still under preview. The samples shown below are not for production environments, unless the SPFx is fully available for use.
The property definition might be changing, since the SPFx is still under preview. The samples shown below are not for production environments, unless the SPFx is fully available for use.
The method PropertyPaneSlider(targetProperty,properties) will create the property in SPFx Web part properties pane. TargetProperty denotes the property name (identifier). The properties denote the property customizations. They contain,
- label - Text to be displayed on the property.
- min - Numeric minimum value of slider.
- max - Numeric maximum value of slider.
- step - Difference between the adjacent values (optional).
- value - Initial value (optional).
- showValue - Boolean, To show the value? (optional)
- disabled - Boolean, to be disabled? (optional)
Implementation
Let us look at the implementation. Let us retrieve SharePoint items from SharePoint list, using the slider value. Here, the number of items retrieved are controlled, using the slider property.
The property is defined in the getPropertyPaneConfiguration method of the Web part property class. The snippet given below shows the property definition. Other properties can also be added.
- protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration {
- return {
- pages: [
- {
- header: {
- description: strings.PropertyPaneDescription
- },
- groups: [
- {
- groupName: strings.BasicGroupName,
- groupFields: [
- PropertyPaneSlider('sliderproperty',{
- label:"Max Items",
- min:5,
- max:20,
- value:5,
- showValue:true,
- step:1
- })
- ]
- }
- ]
- }
- ]
- };
- }
The property value can be retrieved, using the property name under the properties collection (this.properties.sliderproperty). Remember, this property name should be defined in Web part properties file. This has been explained in my previous article.
The custom methods are used to retrieve the data from SharePoint list. The filter is applied with the help of the slider value to the REST API to control the list items count. The methods given below shows the implementation.

Divesh GuptaPosted Mar 30, 2020, 8:24 AM
Hey! I would like to create a react slider which reads from a list. The list can have a Title & Description and I would like to read the two fields and read data to show. Users can slide thru for list items and read. Can you help with that?