Skip to content

Commit

Permalink
fix auto focus in animated dialogs
Browse files Browse the repository at this point in the history
  • Loading branch information
fgilde committed Nov 23, 2024
1 parent b4cb56f commit 15aa30b
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 4 deletions.

Large diffs are not rendered by default.

20 changes: 19 additions & 1 deletion MudBlazor.Extensions/wwwroot/js/mudBlazorExtensions.all.js
Original file line number Diff line number Diff line change
Expand Up @@ -1992,7 +1992,10 @@ class MudExDialogHandler extends MudExDialogHandlerBase {
dialog.__extended = true;
dialog.setAttribute('data-mud-extended', true);
dialog.classList.add('mud-ex-dialog');
this.handleAll(dialog);
this.handleAll(dialog);
this.awaitAnimation(() => {
window.MudBlazorExtensions.focusAllAutoFocusElements();
});
if (this.onDone) this.onDone();
}, 50);
}
Expand Down Expand Up @@ -2467,9 +2470,24 @@ window.MudBlazorExtensions = {
MudExDialogNoModalHandler.bringToFront(dialog, true);
}
}
},

focusAllAutoFocusElements: function () {
const elements = document.querySelectorAll('[data-auto-focus="true"]');
elements.forEach(element => {
element.removeAttribute('data-auto-focus');
window.MudBlazorExtensions._originalFocusMethod(element);
});
}


};

window.MudBlazorExtensions.__bindEvents();

// override focus method
window.MudBlazorExtensions._originalFocusMethod = window.Blazor._internal.domWrapper.focus;
Blazor._internal.domWrapper.focus = function (element, preventScroll) {
element.setAttribute('data-auto-focus', 'true');
window.MudBlazorExtensions._originalFocusMethod(element, preventScroll);
}

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions MudBlazor.Extensions/wwwroot/js/mudBlazorExtensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,24 @@ window.MudBlazorExtensions = {
MudExDialogNoModalHandler.bringToFront(dialog, true);
}
}
},

focusAllAutoFocusElements: function () {
const elements = document.querySelectorAll('[data-auto-focus="true"]');
elements.forEach(element => {
element.removeAttribute('data-auto-focus');
window.MudBlazorExtensions._originalFocusMethod(element);
});
}


};

window.MudBlazorExtensions.__bindEvents();

// override focus method
window.MudBlazorExtensions._originalFocusMethod = window.Blazor._internal.domWrapper.focus;
Blazor._internal.domWrapper.focus = function (element, preventScroll) {
element.setAttribute('data-auto-focus', 'true');
window.MudBlazorExtensions._originalFocusMethod(element, preventScroll);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
dialog.__extended = true;
dialog.setAttribute('data-mud-extended', true);
dialog.classList.add('mud-ex-dialog');
this.handleAll(dialog);
this.handleAll(dialog);
this.awaitAnimation(() => {
window.MudBlazorExtensions.focusAllAutoFocusElements();
});
if (this.onDone) this.onDone();
}, 50);
}
Expand Down

0 comments on commit 15aa30b

Please sign in to comment.