@@ -19,10 +19,6 @@ const UIStrings = {
1919 *@description Text on a button to close the infobar and never show the infobar in the future
2020 */
2121 dontShowAgain : 'Don\'t show again' ,
22- /**
23- *@description Text that indicates that a short message can be expanded to a detailed message
24- */
25- showMore : 'Show more' ,
2622 /**
2723 *@description Text to close something
2824 */
@@ -35,21 +31,16 @@ export class Infobar {
3531 element : HTMLElement ;
3632 private readonly shadowRoot : ShadowRoot ;
3733 private readonly contentElement : HTMLDivElement ;
38- private readonly mainRow : HTMLElement ;
39- private readonly detailsRows : HTMLElement ;
40- private hasDetails : boolean ;
41- private detailsMessage : string | Element ;
34+ private detailsRows ?: HTMLElement ;
4235 private readonly infoContainer : HTMLElement ;
4336 private readonly infoMessage : HTMLElement ;
4437 private infoText : HTMLElement ;
4538 private readonly actionContainer : HTMLElement ;
4639 private readonly disableSetting : Common . Settings . Setting < boolean > | null ;
47- private readonly closeContainer : HTMLElement ;
48- private readonly toggleElement : Buttons . Button . Button ;
4940 private readonly closeButton : DevToolsCloseButton ;
5041 private closeCallback : ( ( ) => void ) | null ;
51- #firstFocusableElement: HTMLElement | null = null ;
5242 private parentView ?: Widget ;
43+ mainRow : HTMLElement ;
5344
5445 constructor (
5546 type : Type , text : string , actions ?: InfobarAction [ ] , disableSetting ?: Common . Settings . Setting < boolean > ,
@@ -63,19 +54,13 @@ export class Infobar {
6354 this . shadowRoot = createShadowRootWithCoreStyles ( this . element , { cssFile : infobarStyles } ) ;
6455
6556 this . contentElement = this . shadowRoot . createChild ( 'div' , 'infobar infobar-' + type ) ;
57+ const icon = IconButton . Icon . create ( TYPE_TO_ICON [ type ] , type + '-icon' ) ;
58+ this . contentElement . createChild ( 'div' , 'icon-container' ) . appendChild ( icon ) ;
6659
6760 this . mainRow = this . contentElement . createChild ( 'div' , 'infobar-main-row' ) ;
68- this . detailsRows = this . contentElement . createChild ( 'div' , 'infobar-details-rows hidden' ) ;
69- this . hasDetails = false ;
70- this . detailsMessage = '' ;
71-
7261 this . infoContainer = this . mainRow . createChild ( 'div' , 'infobar-info-container' ) ;
73-
7462 this . infoMessage = this . infoContainer . createChild ( 'div' , 'infobar-info-message' ) ;
7563
76- const icon = IconButton . Icon . create ( TYPE_TO_ICON [ type ] , type + '-icon' ) ;
77- this . infoMessage . appendChild ( icon ) ;
78-
7964 this . infoText = this . infoMessage . createChild ( 'div' , 'infobar-info-text' ) ;
8065 this . infoText . textContent = text ;
8166 ARIAUtils . markAsAlert ( this . infoText ) ;
@@ -104,20 +89,11 @@ export class Infobar {
10489 jslogContext : action . jslogContext ,
10590 variant : buttonVariant ,
10691 } ) ;
107- if ( action . highlight && ! this . #firstFocusableElement) {
108- this . #firstFocusableElement = button ;
109- }
11092 this . actionContainer . appendChild ( button ) ;
11193 }
11294 }
11395
114- this . closeContainer = this . mainRow . createChild ( 'div' , 'infobar-close-container' ) ;
115- this . toggleElement = createTextButton (
116- i18nString ( UIStrings . showMore ) , this . onToggleDetails . bind ( this ) ,
117- { className : 'hidden show-more' , jslogContext : 'show-more' , variant : Buttons . Button . Variant . TEXT } ) ;
118- this . toggleElement . setAttribute ( 'role' , 'link' ) ;
119- this . closeContainer . appendChild ( this . toggleElement ) ;
120- this . closeButton = this . closeContainer . createChild ( 'dt-close-button' , 'close-button' ) ;
96+ this . closeButton = this . contentElement . createChild ( 'dt-close-button' , 'icon-container' ) ;
12197 this . closeButton . setTabbable ( true ) ;
12298 this . closeButton . setSize ( Buttons . Button . Size . SMALL ) ;
12399 ARIAUtils . setDescription ( this . closeButton , i18nString ( UIStrings . close ) ) ;
@@ -133,16 +109,6 @@ export class Infobar {
133109 event . consume ( ) ;
134110 return ;
135111 }
136-
137- if ( event . target !== this . contentElement ) {
138- return ;
139- }
140-
141- if ( event . key === 'Enter' && this . hasDetails ) {
142- this . onToggleDetails ( ) ;
143- event . consume ( ) ;
144- return ;
145- }
146112 } ) ;
147113
148114 this . closeCallback = null ;
@@ -208,23 +174,16 @@ export class Infobar {
208174 this . dispose ( ) ;
209175 }
210176
211- private onToggleDetails ( ) : void {
212- this . detailsRows . classList . remove ( 'hidden' ) ;
213- this . toggleElement . remove ( ) ;
214- this . onResize ( ) ;
215- ARIAUtils . alert (
216- typeof this . detailsMessage === 'string' ? this . detailsMessage : this . detailsMessage . textContent || '' ) ;
217- if ( this . #firstFocusableElement) {
218- this . #firstFocusableElement. focus ( ) ;
219- } else {
220- this . closeButton . focus ( ) ;
221- }
222- }
223-
224177 createDetailsRowMessage ( message : Element | string ) : Element {
225- this . hasDetails = true ;
226- this . detailsMessage = message ;
227- this . toggleElement . classList . remove ( 'hidden' ) ;
178+ if ( ! this . detailsRows ) {
179+ const details = document . createElement ( 'details' ) ;
180+ const summary = details . createChild ( 'summary' ) ;
181+ const triangleIcon = IconButton . Icon . create ( 'arrow-drop-down' ) ;
182+ summary . createChild ( 'div' , 'icon-container' ) . appendChild ( triangleIcon ) ;
183+ this . contentElement . insertBefore ( details , this . mainRow ) ;
184+ summary . appendChild ( this . mainRow ) ;
185+ this . detailsRows = details . createChild ( 'div' , 'infobar-details-rows' ) ;
186+ }
228187 const infobarDetailsRow = this . detailsRows . createChild ( 'div' , 'infobar-details-row' ) ;
229188 const detailsRowMessage = infobarDetailsRow . createChild ( 'span' , 'infobar-row-message' ) ;
230189 if ( typeof message === 'string' ) {
@@ -237,7 +196,6 @@ export class Infobar {
237196}
238197export interface InfobarAction {
239198 text : string ;
240- highlight : boolean ;
241199 delegate : ( ( ) => void ) | null ;
242200 dismiss : boolean ;
243201 buttonVariant ?: Buttons . Button . Variant ;
0 commit comments