@@ -4,15 +4,17 @@ import iconPushPinOff from '@ui5/webcomponents-icons/dist/pushpin-off.js';
4
4
import iconPushPinOn from '@ui5/webcomponents-icons/dist/pushpin-on.js' ;
5
5
import iconArrowDown from '@ui5/webcomponents-icons/dist/slim-arrow-down.js' ;
6
6
import iconArrowUp from '@ui5/webcomponents-icons/dist/slim-arrow-up.js' ;
7
- import { enrichEventWithDetails , useI18nBundle , useStylesheet } from '@ui5/webcomponents-react-base' ;
7
+ import { debounce , enrichEventWithDetails , useI18nBundle , useStylesheet } from '@ui5/webcomponents-react-base' ;
8
8
import { clsx } from 'clsx' ;
9
- import type { CSSProperties } from 'react' ;
10
- import { forwardRef , useCallback , useEffect , useRef } from 'react' ;
9
+ import type { CSSProperties , Dispatch , MouseEvent , SetStateAction } from 'react' ;
10
+ import { forwardRef , useEffect , useRef } from 'react' ;
11
11
import { COLLAPSE_HEADER , EXPAND_HEADER , PIN_HEADER , UNPIN_HEADER } from '../../i18n/i18n-defaults.js' ;
12
12
import { cssVarVersionInfoPrefix , getUi5TagWithSuffix } from '../../internal/utils.js' ;
13
13
import type { CommonProps } from '../../types/index.js' ;
14
- import { Button , ToggleButton } from '../../webComponents/index.js' ;
15
- import type { ButtonDomRef } from '../../webComponents/index.js' ;
14
+ import type { ButtonDomRef } from '../../webComponents/Button/index.js' ;
15
+ import { Button } from '../../webComponents/Button/index.js' ;
16
+ import type { ToggleButtonDomRef , ToggleButtonPropTypes } from '../../webComponents/ToggleButton/index.js' ;
17
+ import { ToggleButton } from '../../webComponents/ToggleButton/index.js' ;
16
18
import { classNames , styleData } from './ObjectPageAnchorBar.module.css.js' ;
17
19
18
20
const _buttonBaseMinWidth = `${ cssVarVersionInfoPrefix } button_base_min_width` ;
@@ -39,15 +41,15 @@ interface ObjectPageAnchorBarPropTypes extends CommonProps {
39
41
/**
40
42
* Set the header to the state pinned.
41
43
*/
42
- setHeaderPinned ?: ( payload : any ) => void ;
44
+ setHeaderPinned ?: Dispatch < SetStateAction < boolean > > ;
43
45
/**
44
46
* Toggles the header content to be hidden or visible .
45
47
*/
46
48
onToggleHeaderContentVisibility : ( e : any ) => void ;
47
49
/**
48
50
* Highlight title when hovered.
49
51
*/
50
- onHoverToggleButton ?: ( e : any ) => void ;
52
+ onHoverToggleButton ?: ( e : MouseEvent < ToggleButtonDomRef > ) => void ;
51
53
/**
52
54
* Defines internally used accessibility properties/attributes.
53
55
*/
@@ -83,30 +85,40 @@ const ObjectPageAnchorBar = forwardRef<HTMLElement, ObjectPageAnchorBarPropTypes
83
85
const shouldRenderHeaderPinnableButton = ! hidePinButton && headerContentVisible ;
84
86
const showBothActions = shouldRenderHeaderPinnableButton ;
85
87
86
- const onPinHeader = useCallback (
87
- ( e ) => {
88
- setHeaderPinned ( e . target . pressed ) ;
89
- } ,
90
- [ setHeaderPinned ]
91
- ) ;
88
+ const onPinHeader : ToggleButtonPropTypes [ 'onClick' ] = ( e ) => {
89
+ const target = e . target as ToggleButtonDomRef ;
90
+ setHeaderPinned ( target . pressed ) ;
91
+ } ;
92
+
93
+ // debounced because of StrictMode
94
+ const debouncedOnPinButtonToggle = debounce ( ( pinned : boolean ) => {
95
+ onPinButtonToggle ( pinned ) ;
96
+ } , 300 ) ;
92
97
93
98
const isInitial = useRef ( true ) ;
94
99
useEffect ( ( ) => {
95
- if ( ! isInitial . current && typeof onPinButtonToggle === 'function' ) {
96
- onPinButtonToggle ( headerPinned ) ;
100
+ if ( ! isInitial . current && typeof onPinButtonToggle === 'function' && headerPinned != null ) {
101
+ debouncedOnPinButtonToggle ( headerPinned ) ;
97
102
}
98
103
if ( isInitial . current ) {
99
104
isInitial . current = false ;
100
105
}
106
+
107
+ return ( ) => {
108
+ debouncedOnPinButtonToggle . cancel ( ) ;
109
+ } ;
101
110
} , [ headerPinned ] ) ;
102
111
103
112
useEffect ( ( ) => {
104
113
const tagName = getUi5TagWithSuffix ( 'ui5-button' ) ;
105
114
const showHideHeaderBtn = showHideHeaderBtnRef . current ;
106
115
void customElements . whenDefined ( tagName ) . then ( ( ) => {
107
116
if ( showHideHeaderBtn ) {
108
- //@ts -expect-error: for some reason these optional attributes are mandatory which is not expected
109
- showHideHeaderBtn . accessibilityAttributes = { expanded : ! ! headerContentVisible } ;
117
+ showHideHeaderBtn . accessibilityAttributes = {
118
+ expanded : ! ! headerContentVisible ,
119
+ hasPopup : undefined ,
120
+ controls : undefined
121
+ } ;
110
122
}
111
123
} ) ;
112
124
} , [ ! ! headerContentVisible ] ) ;
0 commit comments