11import { ResizeController } from '@lit-labs/observers/resize-controller.js' ;
22import { html , LitElement , nothing , unsafeCSS } from 'lit' ;
33import { customElement , property } from 'lit/decorators.js' ;
4+ import { classMap } from 'lit/directives/class-map.js' ;
45import type { Ref } from 'lit/directives/ref.js' ;
56import { createRef , ref } from 'lit/directives/ref.js' ;
67import { styleMap } from 'lit/directives/style-map.js' ;
@@ -63,9 +64,25 @@ export class MutationTestReportDrawer extends LitElement {
6364 event . stopImmediatePropagation ( ) ;
6465 } ;
6566
67+ connectedCallback ( ) : void {
68+ super . connectedCallback ( ) ;
69+ window . addEventListener ( 'keydown' , this . #handleKeyDown) ;
70+ }
71+
72+ disconnectedCallback ( ) : void {
73+ window . removeEventListener ( 'keydown' , this . #handleKeyDown) ;
74+ super . disconnectedCallback ( ) ;
75+ }
76+
77+ #handleKeyDown = ( event : KeyboardEvent ) => {
78+ if ( event . key === 'Escape' ) {
79+ this . mode = 'closed' ;
80+ }
81+ } ;
82+
6683 render ( ) {
67- const contentHeight = this . #contentHeightController . value ;
68- const styles = styleMap ( { height : contentHeight ? ` ${ contentHeight } px` : undefined } ) ;
84+ const isOpen = this . mode === 'open' ;
85+ const height = this . #contentHeightController . value ;
6986
7087 return html `< aside @click ="${ ( event : Event ) => event . stopPropagation ( ) } " class ="ml-6 mr-4 ">
7188 < header class ="w-full py-4 " ${ ref ( this . #headerRef) } >
@@ -77,7 +94,10 @@ export class MutationTestReportDrawer extends LitElement {
7794 ) }
7895 </ h2 >
7996 </ header >
80- < div style ="${ styles } " class ="mb-4 overflow-y-auto motion-safe:transition-max-width ">
97+ < div
98+ style ="${ height && isOpen ? `height: ${ height } px;` : nothing } "
99+ class ="${ classMap ( { [ 'mb-4 motion-safe:transition-max-width' ] : true , 'overflow-y-auto' : isOpen } ) } "
100+ >
81101 < slot name ="summary "> </ slot >
82102 ${ renderIf ( this . hasDetail && this . mode === 'open' , html `< slot name ="detail "> </ slot > ` ) }
83103 </ div >
0 commit comments