wtc-modal-view 3.3.0
A simple, unopinionated modal class.
A Modal class which can display programatically-generated content, or pull in content from an existing DOM node.
const myModal = new Modal();
const triggerButton = document.querySelector('trigger');
myModal.optionalClass = "modal--myModal";
myModal.content = '<p>Some sample content!</p>';
myModal.focusOnClose = triggerButton;
triggerButton.addEventListener('click', () => {
myModal.open();
});
Void
Closes modal, removes content and optional class, and shifts user focus back to triggering element, if specified.
Void
Opens modal, adds content and optional CSS class
Void
Shifts focus to the first element inside the content
Void
Shifts focus to the last element inside the content
Void
Gets the element that will be focused when the modal closes
HTMLElement
Sets the element that will be focused when the modal closes.
Setter. Usage: modalInstance.focusOnClose = myElement
Name | Type | Description | |
---|---|---|---|
element | HTMLElement |
Must be a focusable element |
Void
Gets the function that is called when the modal opens
Function
Sets the function that is called when the modal opens.
Setter. Usage: modalInstance.onOpen = myFunction
Name | Type | Description | |
---|---|---|---|
callback | Function |
Void
Get the function that is called when the modal closes
Function
Sets the function that is called when the modal closes.
Setter. Usage: modalInstance.onClose = myFunction
Name | Type | Description | |
---|---|---|---|
callback | Function |
Void
Get the function that is called just before the modal closes
Function
Sets the function that is called just before the modal closes.
If this is set, when modalInstance.close()is called it will run the set function with a callback. It will then wait for that callback to be run before completing the close function and calling onClose. Setter. Usage:
modalInstance.onClose = (cb) => {
// do some animation
cb();
}
modalInstance.close(); `
Name | Type | Description | |
---|---|---|---|
callback | Function |
Void
Sets an optional class name on the modal for custom styling.
Setter. Usage: modalInstance.optionalClass = "modal--myclass"
Name | Type | Description | |
---|---|---|---|
className | String Array |
Void
Gets the optional class name
String
Array
optionalClass
Sets the content of the close button, useful for localizing.
Setter. Usage: modalInstance.closeButtonContent = "<String of HTML!>"
Name | Type | Description | |
---|---|---|---|
content | string HTMLElement |
Void
Sets the content of the modal.
Setter. Usage: modalInstance.content = MyHTMLElement
Name | Type | Description | |
---|---|---|---|
content | string HTMLElement |
Void
Documentation generated with doxdox.