Giter VIP home page Giter VIP logo

sp-dev-training-spfx-webpart-proppane's Introduction

Microsoft SharePoint Framework Training Module - Working with the Web Part Property Pane

This module will introduce you to leveraging the property pane for client-side web parts.

This module is also published as a Microsoft Learn module: Enable SharePoint Framework Web Part Configuration with Property Panes

Lab - Working with the Web Part Property Pane

The lab for this module is available in multiple units within the associated Microsoft Learn module. Use the following links to jump to the specific unit. Each Microsoft Learn unit represents a different lab exercise & demo in the presentation.

  1. Exercise - Work with the web part property pane

    In this exercise, you'll manipulate the property pane for a SharePoint Framework client-side web part with controls, groups, and pages.

  2. Exercise - Build custom property pane fields

    In this exercise, you'll extend the property pane by creating your own custom field control.

  3. Exercise - Use the SPFx PnP reusable property pane controls

    In this exercise, you'll learn how to use existing third-party controls from the popular PnP SPFx reusable property pane controls project.

Demos

Watch the Module - Video

This module has been recorded and is available in the SharePoint Development YouTube channel: SharePoint Framework Training - Developing with the SharePoint Framework: Working with the Web Part Property Pane

Contributors

Roles Author(s)
Lab Manuals / Slides Andrew Connell (Microsoft MVP, Voitanos) @andrewconnell
QA Rob Windsor (Microsoft MVP) @rob-windsor
Sponsor / Support Vesa Juvonen (Microsoft) @VesaJuvonen

Version history

Version Date Comments
1.20 June 13, 2024 FY2024Q4 content refresh; update to SPFx v1.19.0
1.19 May 5, 2023 FY2023Q4 content refresh; update to SPFx v1.17.1
1.18 February 28, 2023 FY2023Q3 content refresh; update to SPFx v1.16.1
1.17 December 5, 2022 FY2023Q1 content refresh
1.16 September 5, 2022 FY2023Q1 content refresh; updated for SPFx v1.15.2
1.15 May 2, 2022 FY2022Q3 content refresh; updated for SPFx v1.14
1.14 March 7, 2022 FY2022Q3 content refresh
1.13 December 8, 2021 FY2022Q2 content refresh; retire local workbench
1.12 September 13, 2021 FY2022Q1 content refresh
1.11 June 17, 2021 FY2021Q4 content refresh
1.10 March 6, 2021 FY2021Q3 content refresh
1.9 November 30, 2020 FY2021Q2 content refresh
1.8 August 31, 2020 FY2021Q1 content refresh
1.7 March 10, 2020 FY2020Q3 content refresh & port module to MS Learn
1.6 December 6, 2019 FY2020Q2 content refresh
1.5 September 2, 2019 FY2020Q1 content refresh
1.4 May 29, 2019 FY2019Q4 content refresh
1.3 March 6, 2019 FY2019Q3 Content refresh
1.2 January 17, 2019 Slide updates, added screencast link to readme
1.1 December 12, 2018 Rewritten to use latest guidance
1.0 ~February 2017 Initial release

Disclaimer

THIS CODE IS PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

sp-dev-training-spfx-webpart-proppane's People

Contributors

andrewconnell avatar hugoabernier avatar microsoft-github-policy-service[bot] avatar microsoftopensource avatar msftgits avatar rob-windsor avatar vesajuvonen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sp-dev-training-spfx-webpart-proppane's Issues

Custom Continent Selector Component returns blank when changed - fix proposed

I was watching the video here and I believe I have found a bug when creating the Custom Continent Selector Component.

When I started the project I did create my project from scratch, not from the repo. I believe the repo project was created with No framework. I created mine with React, then placed the code in appropriate spots to compensate. The first demo, without the Custom Component, worked without issue. However, at the end of the Custom Component demo everything seemed to work. However, when the Custom Component dropdown changed the value in the web part was blank.

After some troubleshooting I found, I believe, a bug in the .../src/controls/PropertyPaneContientSelector/components/ContinentSelector.tsx, specifically in the onChanged function:

  private onChanged(option: IDropdownOption, index?: number): void {
    this.selectedKey = option.key;
    const options: IDropdownOption[] = this.state.options;
    options.forEach((opt: IDropdownOption): void => {
      if (opt.key !== option.key) {
        opt.selected = false;
      }
    });
    this.setState((prevState: IContinentSelectorState, props: IContinentSelectorProps): IContinentSelectorState => {
      prevState.options = options;
      return prevState;
    });
    if (this.props.onChanged) {
      this.props.onChanged(option, index);
    }
  }

The last if statement is not reachable in any scenario, thus the component never updates - it should be:

    private onChanged(option: IDropdownOption, index?: number): void {
        this.selectedKey = option.key;
        const options: IDropdownOption[] = this.state.options;
        options.forEach((opt: IDropdownOption): void => {
            if(opt.key !== option.key) {
                opt.selected = false;
            }
        });
        if (this.props.onChanged) {
            this.props.onChanged(option, index);
        }
        this.setState((prevState: IContinentSelectorState, props: IContinentSelectorProps): IContinentSelectorState => {
            prevState.options = options;
            return prevState;
        });

    }

Once the if statement is moved then the if statement can be evaluated and onChanged can be fired resulting in the updating of the component.

Side note - I added Oceania and Europe to the continents :)

Cheers

Webpart sample under folder '02-custom-fields' not getting loaded to workbench.

When I tried to run the webpart project sample for 'custom property pane field using React & Fluent UI' (folder: 02-custom-fields), gulp serve completed successfully but the webpart is not getting loaded to page. Getting the below error.

image

I haven't made any changes to the project. Just did npm install on the project folder and tried to gulp serve the webpart.

Error importing custom control -- index.ts is not a module

Unable to build the project due to the following import errors.

[12:27:29] Error - [tsc] src/controls/PropertyPaneContinentSelector/PropertyPaneContentSelector.ts(14,8): error TS2306: File '.../HelloWorldWP-new/src/controls/PropertyPaneContinentSelector/index.ts' is not a module.
[12:27:29] Error - [tsc] src/webparts/helloWorld/HelloWorldWebPart.ts(22,8): error TS2306: File '.../HelloWorldWP-new/src/controls/PropertyPaneContinentSelector/index.ts' is not a module.
[12:27:29] Error - 'tsc' sub task errored after 5.74 s
exited with code 2

Note that when hovering over the import path './' the word 'index' is appended.

image

Property value not reverted back after clicking discard on page

I've noticed a new bug in a web part we have, can anyone confirm and advise if it is occurring to them as well? I'm trying to rule out a bug in our code.

Using SPFx 1.8.2 on SharePoint Online.

Scenario is pretty straight forward: a web part property that is updated using a custom designer (not in the built in property pane).

The property value is set using this code:

  private setPropertiesValue(propertyPath: string, newValue: any, skipRender: boolean = false) {
    const oldValue: any = get(this.properties, propertyPath);
    update(this.properties, propertyPath, () => newValue);
    if (skipRender !== true)
      this.render();
  }

the property value is a complex object ( not a string, something like {title:"hello", description:"welcome!"} )

Observed behavior

The bug we are noticing is this:

  1. add the web part to the page, using setPropertiesValue set this.properties.prop1 = {title: "hello v1"}
  2. Save, publish, refresh - works as expected
  3. edit the page, change the property using setPropertiesValue set this.properties.prop1 = {title: "hello v2"}
  4. Click discard changes
  5. The web part will display "hello v2" until the user refresh the page, then "hello v1" will be displayed

In edit mode, the webpart just renders 2 textboxes into its content and calling setPropertiesValue when the user changes their value.

Important to note

When clicking discard, the constructor is called followed by OnInit.
Checking this.properites during OnInit will show this.properties.prop1.title = "hello v2" which is the incorrect value, since the user discarded this change.

Expected behavior

after clicking discard on the page I expected OnInit to be called with this.properties.prop1.title = "hello v1"

Any help, or confirmation if this issue happens/doesn't happen to you as well would be very helpful!
I was able to see this issue in several web parts, but some OOB web parts do not have this bug.

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.