SPFx Property Panes: Building Configurable Web Parts

On this page

Property panes let users configure your SPFx web parts without touching code. Here’s how to build them effectively.

Basic Property Pane

TypeScript15 lines
protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration {
  return {
    pages: [{
      header: { description: "Settings" },
      groups: [{
        groupName: "Display Options",
        groupFields: [
          PropertyPaneTextField('title', { label: 'Title' }),
          PropertyPaneToggle('showHeader', { label: 'Show Header' }),
          PropertyPaneSlider('itemCount', { label: 'Items', min: 1, max: 50 })
        ]
      }]
    }]
  };
}

Property Types

  • TextField: Text input
  • Toggle: Boolean switch
  • Dropdown: Select from options
  • Slider: Numeric range
  • Checkbox: Multiple selections

Accessing Properties

TypeScript8 lines
public render(): void {
  const element = React.createElement(MyComponent, {
    title: this.properties.title,
    showHeader: this.properties.showHeader,
    itemCount: this.properties.itemCount
  });
  ReactDom.render(element, this.domElement);
}

References


Discover more from C4: Container, Code, Cloud & Context

Subscribe to get the latest posts sent to your email.

Written by

Nithin Mohan TK

Hello Namaste! 👋🏻 I'm an accomplished Enterprise Solution Architect & Engineering Leader with 20+ years of progressive experience architecting, building, and scaling transformative enterprise solutions. ⚜️ Solution Architect / AI & Cloud 📌 Galway, Ireland

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.