@@ -28,8 +28,8 @@ import { KBQ_LOCALE_SERVICE, KbqRectangleItem, ruRULocaleData } from '@koobiq/co
2828import { KbqDropdownTrigger } from '@koobiq/components/dropdown' ;
2929import { KbqNotificationCenterTrigger } from '@koobiq/components/notification-center' ;
3030import { KbqPopoverTrigger } from '@koobiq/components/popover' ;
31- import { BehaviorSubject , combineLatest , merge , Observable , Subject , Subscription } from 'rxjs' ;
32- import { startWith } from 'rxjs/operators' ;
31+ import { BehaviorSubject , EMPTY , filter , merge , Observable , Subject , Subscription , timer } from 'rxjs' ;
32+ import { delay , startWith , switchMap , takeUntil , tap } from 'rxjs/operators' ;
3333import {
3434 KbqNavbarFocusableItemEvent ,
3535 KbqNavbarIcFocusableItem ,
@@ -43,6 +43,12 @@ export enum KbqExpandEvents {
4343 hoverOrFocus
4444}
4545
46+ /** minimum timeout to use KBQ_ENTER_DELAY */
47+ export const KBQ_MIN_TIMEOUT_FOR_ENTER_DELAY = 2000 ;
48+
49+ /** delay before open navbar-ic */
50+ export const KBQ_ENTER_DELAY = 400 ;
51+
4652/** default configuration of navbar-ic */
4753/** @docs -private */
4854export const KBQ_NAVBAR_IC_DEFAULT_CONFIGURATION = ruRULocaleData . navbarIc ;
@@ -218,6 +224,8 @@ export class KbqNavbarIc extends KbqFocusable implements AfterContentInit {
218224
219225 readonly externalConfiguration = inject ( KBQ_NAVBAR_IC_CONFIGURATION , { optional : true } ) ;
220226
227+ readonly state = new BehaviorSubject < 'expanded' | 'collapsed' | null > ( null ) ;
228+
221229 configuration ;
222230
223231 /** @docs -private */
@@ -276,6 +284,8 @@ export class KbqNavbarIc extends KbqFocusable implements AfterContentInit {
276284 set expanded ( value : boolean ) {
277285 this . _expanded = value ;
278286
287+ this . state . next ( value || this . pinned || this . hasOpenedPopUp ? 'expanded' : 'collapsed' ) ;
288+
279289 this . updateExpandedStateForItems ( ) ;
280290 }
281291
@@ -299,24 +309,55 @@ export class KbqNavbarIc extends KbqFocusable implements AfterContentInit {
299309 return this . expanded ? this . expandedWidth : this . collapsedWidth ;
300310 }
301311
312+ private lastOpeningTime : number ;
313+
302314 constructor ( ) {
303315 super ( ) ;
304316
305- this . animationDone . pipe ( takeUntilDestroyed ( ) ) . subscribe ( this . updateTooltipForItems ) ;
306-
307317 effect ( this . updateExpandedStateForItems ) ;
308318
309- combineLatest ( [ this . hovered , this . focused ] )
310- . pipe ( takeUntilDestroyed ( ) )
311- . subscribe ( ( [ hovered , focused ] ) => {
312- if ( this . pinned ) return ;
319+ this . focused
320+ . pipe (
321+ delay ( 0 ) ,
322+ filter ( ( ) => ! this . pinned || ! this . hasOpenedPopUp ) ,
323+ takeUntilDestroyed ( )
324+ )
325+ . subscribe ( ( focused ) => {
326+ if ( this . hovered . value ) return ;
313327
314328 this . expandEvent = KbqExpandEvents . hoverOrFocus ;
315- this . expanded = hovered || focused ;
329+ this . expanded = focused ;
316330
317331 this . changeDetectorRef . markForCheck ( ) ;
318332 } ) ;
319333
334+ this . hovered
335+ . pipe (
336+ filter ( ( ) => ! this . pinned ) ,
337+ switchMap ( ( hovered ) => {
338+ if ( ! hovered ) {
339+ if ( this . expanded ) {
340+ this . lastOpeningTime = Date . now ( ) ;
341+ }
342+
343+ this . expanded = false ;
344+
345+ return EMPTY ;
346+ }
347+
348+ return timer ( this . getExpandDelay ( ) ) . pipe (
349+ tap ( ( ) => {
350+ this . expandEvent = KbqExpandEvents . hoverOrFocus ;
351+ this . expanded = true ;
352+ this . changeDetectorRef . markForCheck ( ) ;
353+ } ) ,
354+ takeUntil ( this . hovered . pipe ( filter ( ( h ) => ! h ) ) )
355+ ) ;
356+ } ) ,
357+ takeUntilDestroyed ( )
358+ )
359+ . subscribe ( ) ;
360+
320361 this . focusMonitor . monitor ( this . elementRef , true ) . subscribe ( ( focusOrigin ) => {
321362 this . focused . next ( focusOrigin === 'keyboard' ) ;
322363 } ) ;
@@ -366,6 +407,10 @@ export class KbqNavbarIc extends KbqFocusable implements AfterContentInit {
366407 }
367408 }
368409
410+ private getExpandDelay ( ) {
411+ return Date . now ( ) - this . lastOpeningTime < KBQ_MIN_TIMEOUT_FOR_ENTER_DELAY ? 0 : KBQ_ENTER_DELAY ;
412+ }
413+
369414 protected updateTooltipForItems = ( ) => this . items ( ) . forEach ( ( item ) => item . updateTooltip ( ) ) ;
370415
371416 protected updateExpandedStateForItems = ( ) => this . rectangleElements ( ) . forEach ( this . updateItemExpandedState ) ;
0 commit comments