For that we found we can set “IsBlocking” flag to true. We applied the code as mentioned below:
export default class ColorPickerDialog extends BaseDialog {
public message: string;
public colorCode: IColor;
public render(): void {
ReactDOM.render(<ColorPickerDialogContent
close={ this.close }
message={ this.message }
defaultColor={ this.colorCode }
submit={ this._submit }
/>, this.domElement);
}
public getConfig(): IDialogConfiguration {
return { isBlocking: false };
}
protected onAfterClose(): void {
super.onAfterClose();
// Clean up the element for the next dialog
ReactDOM.unmountComponentAtNode(this.domElement);
}
private _submit = (color: IColor) => {
this.colorCode = color;
this.close();
}
}
But still, that does not work.The blog was written in 2017. So, we thought with the updates in SPFx version, there might be change in the code. We tried to find online if we can get any updated code for the same. But we are not able to find it anywhere. So, we decide to put a query in GitHub for solution. We found an old issue there which provide us the resolution.
Resolution:
const dialog: ColorPickerDialog = new ColorPickerDialog({isBlocking: true});
So, the full code for the button click will look something like below:
@override
public onExecute(event: IListViewCommandSetExecuteEventParameters): void {
switch (event.itemId) {
case 'COMMAND_1':
Dialog.alert(`${this.properties.sampleTextOne}`);
// actual code provided in the code
//const dialog: ColorPickerDialog = new ColorPickerDialog();
//code that needs to be updated.
const dialog: ColorPickerDialog = new ColorPickerDialog({isBlocking: true});
dialog.message = 'Pick a color:';
// Use 'FFFFFF' as the default color for first usage
let defaultColor : IColor = { hex: 'FFFFFF', str: '', r: null, g: null, b: null, h: null, s: null, v: null };
dialog.colorCode = this._colorCode|| defaultColor;
dialog.show().then(() => {
this._colorCode = dialog.colorCode;
Dialog.alert(`Picked color: ${dialog.colorCode.hex}`);
});
break;
default:
throw new Error('Unknown command');
}
}
You can remove getConfig() method from ColorPickerDialog class as it is of no use.
It has been 6 years since the posting of the issue and still the blog is not updated. There isn’t any other resource that mentioned this. So, I am writing this again to help anyone who is stuck in the issue.
References: