mount method
Adds this element to the tree as a child of parent.
Implementation
@override
void mount(Element? parent) {
super.mount(parent);
final modal = widget as ModalOverlay;
// Clear any previous focus from the modal nodes to ensure a fresh start
for (final node in modal.modalFocusNodes) {
node.unfocus();
}
// Safely attach focus children during mounting
for (final node in modal.modalFocusNodes) {
modal.focusNode.addChild(node);
}
// Always focus the first child node when mounting the modal
if (modal.modalFocusNodes.isNotEmpty) {
modal.modalFocusNodes.first.requestFocus();
} else {
modal.focusNode.requestFocus();
}
}