This repository was archived by the owner on May 20, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change 1+ // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2+ // for details. All rights reserved. Use of this source code is governed by a
3+ // BSD-style license that can be found in the LICENSE file.
4+
5+ import 'dart:async' ;
6+ import 'dart:html' ;
7+
8+ import 'package:angular/angular.dart' ;
9+
10+ /// Directive to listen to the escape key globally.
11+ ///
12+ /// Useful for things like having a dialog close when the escape key is pressed
13+ /// even when the dialog is not focused.
14+ ///
15+ /// WARNING: If listeners to the onEscape stream are on the page but hidden,
16+ /// they will still be registered to the stream. To avoid that situation, use
17+ /// this directive only within a deferredContent directive.
18+ @Directive (selector: '[globalEscape]' )
19+ class GlobalEscapeDirective {
20+ final Window _window;
21+
22+ /// Event triggered when the escape key is pressed.
23+ @Output ()
24+ Stream <KeyboardEvent > get globalEscape =>
25+ _window.onKeyUp.where ((event) => event.keyCode == KeyCode .ESC );
26+
27+ GlobalEscapeDirective (this ._window);
28+ }
You can’t perform that action at this time.
0 commit comments