Skip to content

Commit

Permalink
fix(instances): check for Modal and Drawer instance existence
Browse files Browse the repository at this point in the history
  • Loading branch information
zoltanszogyenyi committed Oct 31, 2023
1 parent 9cbdb65 commit 21c0060
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 22 deletions.
41 changes: 26 additions & 15 deletions src/components/drawer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,21 +273,32 @@ export function initDrawers() {
'data-drawer-edge-offset'
);

new Drawer($drawerEl, {
placement: placement ? placement : Default.placement,
bodyScrolling: bodyScrolling
? bodyScrolling === 'true'
? true
: false
: Default.bodyScrolling,
backdrop: backdrop
? backdrop === 'true'
? true
: false
: Default.backdrop,
edge: edge ? (edge === 'true' ? true : false) : Default.edge,
edgeOffset: edgeOffset ? edgeOffset : Default.edgeOffset,
} as DrawerOptions);
if (
!instances.instanceExists(
'Drawer',
$drawerEl.getAttribute('id')
)
) {
new Drawer($drawerEl, {
placement: placement ? placement : Default.placement,
bodyScrolling: bodyScrolling
? bodyScrolling === 'true'
? true
: false
: Default.bodyScrolling,
backdrop: backdrop
? backdrop === 'true'
? true
: false
: Default.backdrop,
edge: edge
? edge === 'true'
? true
: false
: Default.edge,
edgeOffset: edgeOffset ? edgeOffset : Default.edgeOffset,
} as DrawerOptions);
}
} else {
console.error(
`Drawer with id ${drawerId} not found. Are you sure that the data-drawer-target attribute points to the correct drawer id?`
Expand Down
18 changes: 11 additions & 7 deletions src/components/modal/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,17 @@ export function initModals() {
const placement = $modalEl.getAttribute('data-modal-placement');
const backdrop = $modalEl.getAttribute('data-modal-backdrop');

new Modal(
$modalEl as HTMLElement,
{
placement: placement ? placement : Default.placement,
backdrop: backdrop ? backdrop : Default.backdrop,
} as ModalOptions
);
if (
!instances.instanceExists('Modal', $modalEl.getAttribute('id'))
) {
new Modal(
$modalEl as HTMLElement,
{
placement: placement ? placement : Default.placement,
backdrop: backdrop ? backdrop : Default.backdrop,
} as ModalOptions
);
}
} else {
console.error(
`Modal with id ${modalId} does not exist. Are you sure that the data-modal-target attribute points to the correct modal id?.`
Expand Down

0 comments on commit 21c0060

Please sign in to comment.