From SPFx version 1.19.0 PropertyPaneCustomField is excluded from the
'@microsoft/sp-property-pane' package. (mentioned in node_modules@microsoft\sp-property-pane\dist\index-internal.d.ts. Many others are also excluded.)
No idea why.! But Microsoft learn documentation still teaches us to use it even in SPFx v1.19.0
Below text is copied from Chat GPT response (for my own reference :-)).
Old Approach
In the earlier versions of SPFx, creating a custom field involved the following steps:
Define the Custom Field: You would define the custom field by implementing the IPropertyPaneCustomFieldProps
interface. This interface includes properties like key
, onRender
, and onDispose
.
Implement the Custom Field: You would then implement the custom field by creating a function that returns an object of type IPropertyPaneField<IPropertyPaneCustomFieldProps>
. This function would handle the rendering and disposal of the custom field.
Use the Custom Field: Finally, you would use the custom field in your web part's property pane configuration by calling the function you created and passing the necessary properties.
Here's a simplified example:
import { IPropertyPaneCustomFieldProps, IPropertyPaneField } from '@microsoft/sp-property-pane';
export interface IMyCustomFieldProps extends IPropertyPaneCustomFieldProps {
// Custom properties
}
export function MyCustomField(properties: IMyCustomFieldProps): IPropertyPaneField<IMyCustomFieldProps> {
return {
type: PropertyPaneFieldType.Custom,
targetProperty: properties.key,
properties: {
key: properties.key,
onRender: (elem: HTMLElement) => {
// Custom rendering logic
},
onDispose: (elem: HTMLElement) => {
// Custom disposal logic
}
}
};
}
This approach allowed for a high degree of customization but required more manual setup and handling of the rendering and disposal processes.
Sources:
(1) Build custom controls for the property pane | Microsoft Learn. https://learn.microsoft.com/en-us/sharepoint/dev/spfx/web-parts/guidance/build-custom-property-pane-controls.
(2) SPFx Property Pane Controls - SharePoint & Microsoft Power ... - SPGuides. https://www.spguides.com/sharepoint-client-side-web-part-configurable-properties-in-property-pane-using-spfx/.
(3) @microsoft/sp-property-pane package | Microsoft Learn. https://learn.microsoft.com/en-us/javascript/api/sp-property-pane?view=sp-typescript-latest.