React Data GridPlugin: Dialog
Description
The dialog plugin provides a modal dialog system for Handsontable. It allows you to display custom content in modal dialogs that overlay the table, providing a way to show notifications, error messages, loading indicators, or any other interactive content.
In order to enable the dialog mechanism, Options#dialog option must be set to true
.
The plugin provides several configuration options to customize the dialog behavior and appearance:
content
: The string or HTMLElement content to display in the dialog (default: '')customClassName
: Custom class name to apply to the dialog (default: '')background
: Dialog background variant 'solid' | 'semi-transparent' (default: 'solid')contentBackground
: Whether to show content background (default: false)animation
: Whether to enable animations (default: true)closable
: Whether the dialog can be closed (default: false)a11y
: Object with accessibility options (default object below)
{
role: 'dialog', // Role of the dialog 'dialog' | 'alertdialog' (default: 'dialog')
ariaLabel: 'Dialog', // Label for the dialog (default: 'Dialog')
ariaLabelledby: '', // ID of the element that labels the dialog (default: '')
ariaDescribedby: '', // ID of the element that describes the dialog (default: ''),
}
Example
const MyComponent = () => {
const hotRef = useRef(null);
useEffect(() => {
const hot = hotRef.current.hotInstance;
const dialogPlugin = hot.getPlugin('dialog');
dialogPlugin.show({
content: <div>
<h2>React Dialog</h2>
<p>Dialog content rendered with React</p>
</div>,
closable: true
});
}, []);
return (
<HotTable
ref={hotRef}
settings={{
data: data,
dialog: {
customClassName: 'react-dialog',
closable: true
}
}}
/>
);
}
Options
dialog
Source codedialog.dialog : boolean | object
The dialog
option configures the Dialog
plugin.
You can set the dialog
option to one of the following:
Setting | Description |
---|---|
false | Disable the Dialog plugin |
true | Enable the Dialog plugin with default options |
dialog: Additional options
Option | Possible settings | Description |
---|---|---|
content | A string, HTMLElement or DocumentFragment (default: '' ) | The content of the dialog |
customClassName | A string (default: '' ) | The custom class name of the dialog |
background | One of the options: 'solid' or 'semi-transparent' (default: 'solid' ) | The background of the dialog |
contentBackground | Boolean (default: false ) | Whether to show the content background |
animation | Boolean (default: true ) | Whether to show the animation |
closable | Boolean (default: false ) | Whether to make the dialog closable |
a11y | Object with accessibility options (default: { role: 'dialog', ariaLabel: 'Dialog', ariaLabelledby: '', ariaDescribedby: '' } ) | Accessibility options for the dialog |
Read more:
Default: false
Since: 16.1.0
Example
// enable the Dialog plugin with default option
<HotTable
dialog={true}
/>
// enable the Dialog plugin with custom configuration
<HotTable
dialog={{
content: 'Dialog content',
customClassName: 'custom-dialog',
background: 'semi-transparent',
contentBackground: false,
animation: false,
closable: true,
a11y: {
role: 'dialog',
ariaLabel: 'Dialog',
ariaLabelledby: 'titleID',
ariaDescribedby: 'descriptionID',
}
}
}}
/>
Methods
destroy
Source codedialog.destroy()
Destroy dialog and reset plugin state.
disablePlugin
Source codedialog.disablePlugin()
Disable plugin for this Handsontable instance.
enablePlugin
Source codedialog.enablePlugin()
Enable plugin for this Handsontable instance.
focus
Source codedialog.focus()
Focus the dialog.
hide
Source codedialog.hide()
Hide the currently open dialog. Closes the dialog and restores the focus to the table.
isEnabled
Source codedialog.isEnabled() ⇒ boolean
Check if the plugin is enabled in the handsontable settings.
isVisible
Source codedialog.isVisible() ⇒ boolean
Check if the dialog is currently visible.
Returns: boolean
- True if the dialog is visible, false otherwise.
show
Source codedialog.show(options)
Show dialog with given configuration. Displays the dialog with the specified content and options.
Param | Type | Description |
---|---|---|
options | object | Dialog configuration object containing content and display options. |
options.content | string HTMLElement DocumentFragment | The content to display in the dialog. Can be a string, HTMLElement, or DocumentFragment. Default: '' |
options.customClassName | string | Custom CSS class name to apply to the dialog container. Default: '' |
options.background | 'solid' 'semi-transparent' | Dialog background variant. Default: 'solid'. |
options.contentBackground | boolean | Whether to show content background. Default: false. |
options.animation | boolean | Whether to enable animations when showing/hiding the dialog. Default: true. |
options.closable | boolean | Whether the dialog can be closed by user interaction. Default: false. |
options.a11y | object | Object with accessibility options. |
options.a11y.role | string | The role of the dialog. Default: 'dialog'. |
options.a11y.ariaLabel | string | The label of the dialog. Default: 'Dialog'. |
options.a11y.ariaLabelledby | string | The ID of the element that labels the dialog. Default: ''. |
options.a11y.ariaDescribedby | string | The ID of the element that describes the dialog. Default: ''. |
update
Source codedialog.update(options)
Update the dialog configuration.
Param | Type | Description |
---|---|---|
options | object | Dialog configuration object containing content and display options. |
options.content | string HTMLElement DocumentFragment | The content to display in the dialog. Can be a string, HTMLElement, or DocumentFragment. Default: '' |
options.customClassName | string | Custom CSS class name to apply to the dialog container. Default: '' |
options.background | 'solid' 'semi-transparent' | Dialog background variant. Default: 'solid'. |
options.contentBackground | boolean | Whether to show content background. Default: false. |
options.animation | boolean | Whether to enable animations when showing/hiding the dialog. Default: true. |
options.closable | boolean | Whether the dialog can be closed by user interaction. Default: false. |
options.a11y | object | Object with accessibility options. |
options.a11y.role | string | The role of the dialog. Default: 'dialog'. |
options.a11y.ariaLabel | string | The label of the dialog. Default: 'Dialog'. |
options.a11y.ariaLabelledby | string | The ID of the element that labels the dialog. Default: ''. |
options.a11y.ariaDescribedby | string | The ID of the element that describes the dialog. Default: ''. |
updatePlugin
Source codedialog.updatePlugin()
Update plugin state after Handsontable settings update.