Our HR team wanted a Team Directory on their SharePoint home page: click a name to see details, confirm before removing anyone, edit in place, and add a quick note.
Each is a modal popup in SPFx. The finished web part opens a Fluent UI Modal, a confirmation Dialog, a side Panel and a BaseDialog from SPFx’s dialog package.
In this tutorial, we’ll build all four with Heft, test them in the SPGuides workbench, and map old SP.UI.ModalDialog.showModalDialog code to the modern way, so you can create a modal popup in SPFx for any case.
Here’s what we’re building:

Before You Start
You need SPFx 1.23 (Node.js 22, Yeoman, the SharePoint generator, Heft) and edit rights on a site. New setup? Follow setting up SPFx with the Heft toolchain first. Each popup fits a different job:
| Popup | Package | Best for |
|---|---|---|
| Modal | @fluentui/react | Custom layouts: details cards, forms |
| Dialog | @fluentui/react | Confirmations with OK/Cancel |
| Panel | @fluentui/react | Longer forms that slide in from the right |
| BaseDialog + Dialog.alert | @microsoft/sp-dialog | Extensions and popups opened outside your React tree |
Our sample data is three US employees:
| Name | Job title | Department | Office |
|---|---|---|---|
| Megan Bowen | Marketing Manager | Marketing | Seattle, WA |
| Alex Wilber | Sales Specialist | Sales | Chicago, IL |
| Adele Vance | Retail Manager | Retail | Austin, TX |
Step 1: Create the SPFx React Web Part Project
Run the SharePoint generator for a React web part (your first SPFx web part explains the generated files), then add the dialog package, which the template doesn’t include:
yo @microsoft/sharepoint --solution-name spg-modal-popup --component-type webpart --component-name ModalPopup --framework react --environment spo
npm install @microsoft/sp-dialog@1.23.2 --save-exact
Point config/serve.json at your site’s workbench:
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/spfx-serve.schema.json",
"port": 4321,
"https": true,
"initialPage": "https://{tenantDomain}/sites/SPGuides/_layouts/workbench.aspx"
}
Checkpoint: package.json lists @microsoft/sp-dialog 1.23.2 next to @fluentui/react and react 17.0.1.
Step 2: Add the Sample Data
Create src/webparts/modalPopup/components/IEmployee.ts. A real directory would read SharePoint list items, but a fixed array keeps the focus on the popups:
export interface IEmployee {
id: number;
name: string;
jobTitle: string;
department: string;
office: string;
}
export const EMPLOYEES: IEmployee[] = [
{ id: 1, name: 'Megan Bowen', jobTitle: 'Marketing Manager', department: 'Marketing', office: 'Seattle, WA' },
{ id: 2, name: 'Alex Wilber', jobTitle: 'Sales Specialist', department: 'Sales', office: 'Chicago, IL' },
{ id: 3, name: 'Adele Vance', jobTitle: 'Retail Manager', department: 'Retail', office: 'Austin, TX' }
];
Checkpoint: The file exports IEmployee and EMPLOYEES.
Step 3: Build the Fluent UI Modal (Details Popup)
The Modal is a blank box, so you draw the header, body and footer. Create src/webparts/modalPopup/components/EmployeeModal.tsx:
import * as React from 'react';
import { Modal, ContextualMenu, IconButton, PrimaryButton, mergeStyleSets, FontWeights } from '@fluentui/react';
import { IEmployee } from './IEmployee';
export interface IEmployeeModalProps {
employee: IEmployee | undefined;
onDismiss: () => void;
}
const css = mergeStyleSets({
container: { width: 480, maxWidth: '90vw' },
header: {
display: 'flex', alignItems: 'center', padding: '12px 12px 12px 24px',
fontSize: 20, fontWeight: FontWeights.semibold, borderTop: '4px solid #0078d4', cursor: 'move'
},
body: { padding: '0 24px 8px' },
row: { display: 'flex', padding: '8px 0', borderBottom: '1px solid #edebe9' },
label: { width: 140, fontWeight: FontWeights.semibold, color: '#605e5c' },
footer: { display: 'flex', justifyContent: 'flex-end', gap: 8, padding: '16px 24px 24px' }
});
const EmployeeModal: React.FC<IEmployeeModalProps> = ({ employee, onDismiss }) => {
const titleId = 'employee-modal-title';
return (
<Modal
titleAriaId={titleId}
isOpen={!!employee}
onDismiss={onDismiss}
isBlocking={false}
containerClassName={css.container}
dragOptions={{ moveMenuItemText: 'Move', closeMenuItemText: 'Close', menu: ContextualMenu, dragHandleSelector: '.ms-Modal-dragHandle' }}
>
<div className={`${css.header} ms-Modal-dragHandle`}>
<span id={titleId}>{employee?.name}</span>
<IconButton
iconProps={{ iconName: 'Cancel' }}
ariaLabel="Close popup"
onClick={onDismiss}
styles={{ root: { marginLeft: 'auto' } }}
/>
</div>
<div className={css.body}>
<div className={css.row}><span className={css.label}>Job title</span><span>{employee?.jobTitle}</span></div>
<div className={css.row}><span className={css.label}>Department</span><span>{employee?.department}</span></div>
<div className={css.row}><span className={css.label}>Office</span><span>{employee?.office}</span></div>
</div>
<div className={css.footer}>
<PrimaryButton text="Close" onClick={onDismiss} />
</div>
</Modal>
);
};
export default EmployeeModal;
isOpen shows it, onDismiss runs on Esc, a backdrop click or the X, and dragOptions makes the header draggable.
Checkpoint: No terminal errors; the Modal stays hidden until employee has a value.
Step 4: Create a BaseDialog with @microsoft/sp-dialog
BaseDialog is SPFx’s own popup: you create an object and call show() instead of using JSX, which is why ListView Command Set extensions use it. Create src/webparts/modalPopup/components/NoteDialog.tsx:
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { BaseDialog } from '@microsoft/sp-dialog';
import { DialogContent, DialogFooter, TextField, PrimaryButton, DefaultButton } from '@fluentui/react';
interface INoteDialogContentProps {
employeeName: string;
onSave: (note: string) => void;
onClose: () => void;
}
const NoteDialogContent: React.FC<INoteDialogContentProps> = ({ employeeName, onSave, onClose }) => {
const [note, setNote] = React.useState<string>('');
return (
<DialogContent
title={`Add a note for ${employeeName}`}
subText="Opened with BaseDialog from @microsoft/sp-dialog."
onDismiss={onClose}
showCloseButton={true}
>
<TextField label="Note" multiline rows={3} value={note} onChange={(_e, v) => setNote(v || '')} />
<DialogFooter>
<DefaultButton text="Cancel" onClick={onClose} />
<PrimaryButton text="Save note" disabled={!note.trim()} onClick={() => onSave(note.trim())} />
</DialogFooter>
</DialogContent>
);
};
export default class NoteDialog extends BaseDialog {
public note: string = '';
constructor(private _employeeName: string) {
super({ isBlocking: true });
}
public render(): void {
ReactDOM.render(
<NoteDialogContent
employeeName={this._employeeName}
onSave={this._save}
onClose={this._close}
/>,
this.domElement
);
}
protected onAfterClose(): void {
super.onAfterClose();
ReactDOM.unmountComponentAtNode(this.domElement);
}
private _save = (note: string): void => {
this.note = note;
this.close().catch(() => { /* already closed */ });
};
private _close = (): void => {
this.close().catch(() => { /* already closed */ });
};
}
render() draws into the empty domElement SPFx provides, and onAfterClose() unmounts it so old values don’t come back. Older samples add getConfig(), but the current class has none; pass the config to super().
Checkpoint: show() returns a promise that resolves when the dialog closes, so the caller can read note.
Step 5: Wire Up the Directory, Dialog and Panel
Replace src/webparts/modalPopup/components/ModalPopup.tsx. It renders the table, keeps one state value per popup, and adds the Dialog and Panel inline (more Fluent UI components in SPFx):
import * as React from 'react';
import {
DefaultButton, PrimaryButton, ActionButton, Dialog, DialogType, DialogFooter, Panel, PanelType, TextField
} from '@fluentui/react';
import { Dialog as SPDialog } from '@microsoft/sp-dialog';
import styles from './ModalPopup.module.scss';
import type { IModalPopupProps } from './IModalPopupProps';
import { IEmployee, EMPLOYEES } from './IEmployee';
import EmployeeModal from './EmployeeModal';
import NoteDialog from './NoteDialog';
const ModalPopup: React.FC<IModalPopupProps> = () => {
const [employees, setEmployees] = React.useState<IEmployee[]>(EMPLOYEES);
const [viewing, setViewing] = React.useState<IEmployee | undefined>(undefined);
const [removing, setRemoving] = React.useState<IEmployee | undefined>(undefined);
const [editing, setEditing] = React.useState<IEmployee | undefined>(undefined);
const confirmRemove = (): void => {
setEmployees(employees.filter(e => e.id !== removing?.id));
setRemoving(undefined);
};
const saveEdit = (): void => {
setEmployees(employees.map(e => (e.id === editing?.id ? editing : e)));
setEditing(undefined);
};
const addNote = async (employee: IEmployee): Promise<void> => {
const dialog = new NoteDialog(employee.name);
await dialog.show();
if (dialog.note) {
await SPDialog.alert(`Note saved for ${employee.name}: "${dialog.note}"`);
}
};
return (
<section className={styles.modalPopup}>
<h2>Team Directory</h2>
<table className={styles.grid}>
<thead>
<tr><th>Name</th><th>Job title</th><th>Office</th><th>Actions</th></tr>
</thead>
<tbody>
{employees.map(e => (
<tr key={e.id}>
<td>{e.name}</td>
<td>{e.jobTitle}</td>
<td>{e.office}</td>
<td>
<ActionButton iconProps={{ iconName: 'ContactCard' }} text="View" onClick={() => setViewing(e)} />
<ActionButton iconProps={{ iconName: 'Edit' }} text="Edit" onClick={() => setEditing({ ...e })} />
<ActionButton iconProps={{ iconName: 'QuickNote' }} text="Note" onClick={() => { addNote(e).catch(console.error); }} />
<ActionButton iconProps={{ iconName: 'Delete' }} text="Remove" onClick={() => setRemoving(e)} />
</td>
</tr>
))}
</tbody>
</table>
<EmployeeModal employee={viewing} onDismiss={() => setViewing(undefined)} />
<Dialog
hidden={!removing}
onDismiss={() => setRemoving(undefined)}
dialogContentProps={{
type: DialogType.normal,
title: 'Remove team member?',
subText: `${removing?.name} will be removed from this directory view. You can't undo this.`
}}
modalProps={{ isBlocking: true }}
>
<DialogFooter>
<PrimaryButton text="Remove" onClick={confirmRemove} />
<DefaultButton text="Cancel" onClick={() => setRemoving(undefined)} />
</DialogFooter>
</Dialog>
<Panel
isOpen={!!editing}
type={PanelType.medium}
headerText={`Edit ${editing?.name || ''}`}
onDismiss={() => setEditing(undefined)}
closeButtonAriaLabel="Close"
isFooterAtBottom={true}
onRenderFooterContent={() => (
<div style={{ display: 'flex', gap: 8 }}>
<PrimaryButton text="Save" onClick={saveEdit} />
<DefaultButton text="Cancel" onClick={() => setEditing(undefined)} />
</div>
)}
>
<TextField label="Job title" value={editing?.jobTitle}
onChange={(_ev, v) => editing && setEditing({ ...editing, jobTitle: v || '' })} />
<TextField label="Office" value={editing?.office}
onChange={(_ev, v) => editing && setEditing({ ...editing, office: v || '' })} />
</Panel>
</section>
);
};
export default ModalPopup;
Fluent’s Dialog uses hidden (true = closed), while Modal and Panel use isOpen. The SharePoint Dialog is imported as SPDialog to avoid the name clash.
Checkpoint: Saving the file gives no TypeScript or lint errors.
Step 6: Run the Web Part in the Workbench
Start the local server (Heft since SPFx 1.22, not gulp serve):
$env:SPFX_SERVE_TENANT_DOMAIN = "spguides.sharepoint.com"
npm run start
In the SPGuides workbench (/sites/SPGuides/_layouts/workbench.aspx), select + and search for Team Directory:


The hosted workbench retires on 12/01/2026; after that, test on a modern page with the debug query string npm run start prints.
Checkpoint: Three rows, each with View, Edit, Note and Remove.
Test the Popups
- View opens the Modal shown at the top; Esc closes it.
- Remove opens the blocking Dialog; an overlay click did nothing.
- Edit slides in the Panel; Save updates the row.
- Note opens the BaseDialog; Save note triggers
Dialog.alert().




Classic SP.UI.ModalDialog.showModalDialog: What Replaced It
Before SPFx, you pasted code like this into a Script Editor web part to open a page, often a list form with ?IsDlg=1, in a dialog:
// Classic pages only
function openNewProduct() {
var options = {
url: '/sites/SPGuides/Lists/SPGDemo%20Products/NewForm.aspx?IsDlg=1',
title: 'New product',
width: 640,
height: 460,
allowMaximize: false,
showClose: true,
dialogReturnValueCallback: function (result, value) {
if (result === SP.UI.DialogResult.OK) {
SP.UI.ModalDialog.RefreshPage(result);
}
}
};
SP.SOD.execute('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog', options);
}
// Inside the dialog page
SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.OK, 'saved');
I tested it in the SPGuides site. On the modern home page, typeof SP returns undefined: the classic object model isn’t loaded, and there’s no Script Editor web part. On a classic page (Site Settings), showModalDialog was undefined until SP.SOD.executeFunc('sp.ui.dialog.js', ...) loaded it, then it opened the form:

SharePoint Online has also enforced its Content Security Policy on modern pages since 03/01/2026, blocking inline <script> blocks and onclick= attributes. Here’s the modern mapping:
| Classic (sp.ui.dialog.js) | Modern SPFx |
|---|---|
showModalDialog(options) | new MyDialog().show() or a Fluent UI Modal |
dialogReturnValueCallback | await dialog.show(), then read dialog.note |
commonModalDialogClose() | this.close() inside the BaseDialog |
| Script Editor web part | An SPFx web part, Application Customizer or Command Set |
On a classic page, SP.SOD.execute is still the fix for “showModalDialog is not a function”. For anything new, use SPFx; a modern script editor web part shows what CSP still allows.
Make It Production-Ready
- Two layers max: BaseDialog allows a dialog plus one secondary dialog. More patterns are in our SharePoint Framework tutorials.
- Load data in onBeforeOpen(): not in the constructor; SPFx shows a spinner meanwhile.
- Package:
npm run buildtook 1 minute 51 seconds and createdspg-modal-popup.sppkg.
Troubleshooting
| Problem | Fix |
|---|---|
| TS2741: Property ‘menu’ is missing in type … ‘IDragOptions’ | Add menu: ContextualMenu to dragOptions. |
| Cannot find module ‘@microsoft/sp-dialog’ | Install it; web part projects don’t include it. |
Where to Take It Next
- List toolbar: move the NoteDialog into a Command Set and restrict it to one list.
- Every page: show a welcome BaseDialog from an SPFx Application Customizer.
- Richer forms: add a Fluent UI dropdown bound to list items to the Panel.
A few more SharePoint Framework tutorials you’ll find useful:
Frequently Asked Questions
Can I use BaseDialog from @microsoft/sp-dialog in a web part?
Yes. Microsoft documents it for extensions and client-side web parts; install @microsoft/sp-dialog first. See Microsoft Learn: Use custom dialog boxes with SPFx.
Why doesn’t SP.UI.ModalDialog.showModalDialog work on modern pages?
Modern pages don’t load sp.ui.dialog.js, and SharePoint’s CSP blocks inline script there. Microsoft Learn: Content Security Policy in SharePoint Online lists what’s blocked.
Does IsDlg=1 still work in SharePoint Online?
Partly. In my 10/24/2026 test, NewForm.aspx?IsDlg=1 still returned the classic form without page chrome, but modern pages can’t host it in an SP.UI dialog. Use an SPFx Panel or Modal there.

Hey! I’m Bijay Kumar, founder of SPGuides.com and a Microsoft Business Applications MVP (Power Automate, Power Apps). I launched this site in 2020 because I truly enjoy working with SharePoint, Power Platform, and SharePoint Framework (SPFx), and wanted to share that passion through step-by-step tutorials, guides, and training videos. My mission is to help you learn these technologies so you can utilize SharePoint, enhance productivity, and potentially build business solutions along the way.