blob: 8567a8ce8fab43dc8be670fe61ba0c99f1b58e31 [file]
// Copyright 2025 The Flutter Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file or at https://developers.google.com/open-source/licenses/bsd.
import 'dart:js_interop';
import 'package:web/web.dart';
const _flutterViewSelector = 'flutter-view';
void addBlurListener() {
window.addEventListener('blur', _onBlur.toJS);
}
void removeBlurListener() {
window.removeEventListener('blur', _onBlur.toJS);
}
void _onBlur(Event _) {
final activeElement = document.activeElement as HTMLElement?;
if (activeElement == null) return;
// Only call blur on elements that are within a Flutter view.
final inFlutterView = activeElement.closest(_flutterViewSelector) != null;
if (inFlutterView) {
activeElement.blur();
}
}