Breaking: #98288 - Updated Backend Modal API
See forge#98288
Description
The modal API provided by the module @typo3/
has been
adapted to backed by a custom web component and therefore gained an updated,
stateless interface.
The return type of all Modal.*
factory methods has been changed from
JQuery
to Modal
.
Modal
is a web component which allows to attach modal API
(like modal hiding) directly to the returned object. Usage of globals like
Modal.
can thus be avoided when using the returned
Modal
.
This affects the following methods which now return Modal
:
Modal.
confirm () Modal.
load Url () Modal.
show () Modal.
advanced () Modal.
set Buttons () Modal.
generate ()
Furthermore the following changes have been applied:
- The
Button
propertydata
has been removed without replacement, as the functionality can be expressed viaAttributes Button.
orname Button.
and is therefore redundant.trigger - The
ajax
of the modalTarget Configuration
object has been dropped, as it was never actually used in TYPO3. Use nested, custom web components for dynamic ajax loading of modal sub areas. - The rendering life cycle has been adapted to synchronize rendering to
the browsers idle callback. That means rendering is delayed and modal content
can not be modified directly after modal creation.
The existing API
Configuration.
has to be used instead, but usage of litcallback Template
without the need for post-processing is suggested to be used instead.Result - The
bs.
events are no longer considered API, but remain working for the time being (as bootstrap modal is still used right now). These events may be dropped at any time, when the modal component is switched to shadow dom, or the nativemodal.* <dialog>
tag. Thereforetypo3-
events are to be used instead.modal-* - The event
modal-
has been removed. Usedestroyed typo3-
ormodal- hide typo3-
instead.modal- hidden Modal.
has been removed. Usecurrent Modal. trigger ('modal- dismiss') Modal
instead.Element. hide Modal ()
Impact
Using jQuery API on Modal
will lead to JavaScript errors as
no jQuery interop is provided.
Affected installations
All 3rd party extensions using the API of the @typo3/
module are affected, if they use the return type of the methods to attach
to events or to customize the modal after creations.
Migration
Given the following fully-fledged example of a modal that uses custom buttons,
with custom attributes, triggers and events, they should be migrated away
from JQuery
to Modal
usage.
Existing code:
var configuration = {
buttons: [
{
text: 'Save changes',
name: 'save',
icon: 'actions-document-save',
active: true,
btnClass: 'btn-primary',
dataAttributes: {
action: 'save'
},
trigger: function() {
Modal.currentModal.trigger('modal-dismiss');
}
}
]
};
Modal
.advanced(configuration)
.on('hidden.bs.modal', function() {
// do something
});
Should be adapted to:
const modal = Modal.advanced({
buttons: [
{
text: 'Save changes',
name: 'save',
icon: 'actions-document-save',
active: true,
btnClass: 'btn-primary',
trigger: function(event, modal) {
modal.hideModal();
}
}
]
});
modal.addEventListener('typo3-modal-hidden', function() {
// do something
});