Skip to content

Commit 95a5c68

Browse files
committed
feat(ObjectPage): extend accessibilityAttributes with expandButton
1 parent f9dfa0e commit 95a5c68

File tree

5 files changed

+84
-11
lines changed

5 files changed

+84
-11
lines changed

packages/main/src/components/ObjectPage/ObjectPage.cy.tsx

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,6 +1358,69 @@ describe('ObjectPage', () => {
13581358
});
13591359
});
13601360

1361+
it('accessibilityAttributes', () => {
1362+
cy.mount(
1363+
<ObjectPage data-testid="op" titleArea={DPTitle} headerArea={DPContent} footerArea={Footer}>
1364+
{OPContent}
1365+
</ObjectPage>,
1366+
);
1367+
1368+
cy.get('header').should('not.have.attr', 'role');
1369+
cy.get('header').should('have.attr', 'aria-roledescription', 'Object Page header');
1370+
cy.get('[data-component-name="ObjectPageAnchorBarExpandBtn"]').should(($el) => {
1371+
expect($el[0].accessibilityAttributes.expanded).to.equal(true);
1372+
});
1373+
cy.get('[data-component-name="ObjectPageAnchorBarExpandBtn"]').should(
1374+
'have.attr',
1375+
'accessible-name',
1376+
'Collapse Header',
1377+
);
1378+
cy.get('section[data-component-name="ObjectPageAnchorBar"]').should('not.have.attr', 'role');
1379+
cy.get('footer').should('not.have.attr', 'role');
1380+
1381+
const accessibilityAttributes = {
1382+
objectPageTopHeader: {
1383+
role: 'banner',
1384+
ariaRoledescription: 'ariaRoledescription',
1385+
},
1386+
objectPageAnchorBar: {
1387+
expandButton: {
1388+
expanded: undefined,
1389+
accessibleName: '',
1390+
},
1391+
role: 'not-a-real-role',
1392+
},
1393+
objectPageFooterArea: {
1394+
role: 'contentinfo',
1395+
},
1396+
};
1397+
1398+
cy.mount(
1399+
<ObjectPage
1400+
data-testid="op"
1401+
titleArea={DPTitle}
1402+
headerArea={DPContent}
1403+
footerArea={Footer}
1404+
accessibilityAttributes={accessibilityAttributes}
1405+
>
1406+
{OPContent}
1407+
</ObjectPage>,
1408+
);
1409+
1410+
cy.get('header').should('have.attr', 'role', 'banner');
1411+
cy.get('header').should('have.attr', 'aria-roledescription', 'ariaRoledescription');
1412+
cy.get('[data-component-name="ObjectPageAnchorBarExpandBtn"]').should(($el) => {
1413+
const attrs = $el[0].accessibilityAttributes;
1414+
1415+
expect(attrs).to.exist();
1416+
expect(attrs).to.haveOwnProperty('expanded');
1417+
expect(attrs.expanded).to.equal(undefined);
1418+
});
1419+
cy.get('[data-component-name="ObjectPageAnchorBarExpandBtn"]').should('have.attr', 'accessible-name', '');
1420+
cy.get('section[data-component-name="ObjectPageAnchorBar"]').should('have.attr', 'role', 'not-a-real-role');
1421+
cy.get('footer').should('have.attr', 'role', 'contentinfo');
1422+
});
1423+
13611424
cypressPassThroughTestsFactory(ObjectPage);
13621425
});
13631426

packages/main/src/components/ObjectPage/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ const ObjectPage = forwardRef<ObjectPageDomRef, ObjectPagePropTypes>((props, ref
650650
headerContentVisible={headerArea && headerCollapsed !== true}
651651
hidePinButton={!!hidePinButton}
652652
headerPinned={headerPinned}
653-
accessibilityAttributes={accessibilityAttributes}
653+
accessibilityAttributes={accessibilityAttributes?.objectPageAnchorBar}
654654
onToggleHeaderContentVisibility={onToggleHeaderContentVisibility}
655655
setHeaderPinned={setHeaderPinned}
656656
onHoverToggleButton={onHoverToggleButton}

packages/main/src/components/ObjectPage/types/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { CommonProps, Ui5CustomEvent } from '@ui5/webcomponents-react-base'
33
import type { ReactElement, ReactNode } from 'react';
44
import type { ObjectPageMode } from '../../../enums/ObjectPageMode.js';
55
import type { AvatarPropTypes } from '../../../webComponents/Avatar/index.js';
6+
import type { ButtonPropTypes } from '../../../webComponents/Button/index.js';
67
import type { TabContainerDomRef } from '../../../webComponents/TabContainer/index.js';
78
import type { ObjectPageHeaderPropTypes } from '../../ObjectPageHeader/index.js';
89
import type { ObjectPageSectionPropTypes } from '../../ObjectPageSection/index.js';
@@ -106,7 +107,12 @@ export interface ObjectPagePropTypes extends Omit<CommonProps, 'placeholder'> {
106107
role?: string;
107108
ariaRoledescription?: string;
108109
};
110+
//todo: rename in next major version to better reflect what part of the ObjectPage it describes
109111
objectPageAnchorBar?: {
112+
expandButton?: {
113+
expanded?: ButtonPropTypes['accessibilityAttributes']['expanded'] | undefined;
114+
accessibleName?: ButtonPropTypes['accessibleName'];
115+
};
110116
role?: string;
111117
};
112118
objectPageFooterArea?: {

packages/main/src/components/ObjectPageAnchorBar/index.tsx

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import type { ButtonDomRef } from '../../webComponents/Button/index.js';
1515
import { Button } from '../../webComponents/Button/index.js';
1616
import type { ToggleButtonDomRef, ToggleButtonPropTypes } from '../../webComponents/ToggleButton/index.js';
1717
import { ToggleButton } from '../../webComponents/ToggleButton/index.js';
18+
import type { ObjectPagePropTypes } from '../ObjectPage/types/index.js';
1819
import { classNames, styleData } from './ObjectPageAnchorBar.module.css.js';
1920

2021
const _buttonBaseMinWidth = `${cssVarVersionInfoPrefix}button_base_min_width`;
@@ -53,11 +54,7 @@ interface ObjectPageAnchorBarPropTypes extends CommonProps {
5354
/**
5455
* Defines internally used accessibility properties/attributes.
5556
*/
56-
accessibilityAttributes?: {
57-
objectPageAnchorBar?: {
58-
role?: string;
59-
};
60-
};
57+
accessibilityAttributes?: ObjectPagePropTypes['accessibilityAttributes']['objectPageAnchorBar'];
6158
/**
6259
* Fired when the `headerContent` changes its pinned state.
6360
*/
@@ -114,14 +111,18 @@ const ObjectPageAnchorBar = forwardRef<HTMLElement, ObjectPageAnchorBarPropTypes
114111
const showHideHeaderBtn = showHideHeaderBtnRef.current;
115112
void customElements.whenDefined(tagName).then(() => {
116113
if (showHideHeaderBtn) {
114+
const expanded =
115+
accessibilityAttributes?.expandButton && Object.hasOwn(accessibilityAttributes.expandButton, 'expanded')
116+
? accessibilityAttributes.expandButton.expanded
117+
: !!headerContentVisible;
117118
showHideHeaderBtn.accessibilityAttributes = {
118-
expanded: !!headerContentVisible,
119+
expanded,
119120
hasPopup: undefined,
120121
controls: undefined,
121122
};
122123
}
123124
});
124-
}, [!!headerContentVisible]);
125+
}, [accessibilityAttributes?.expandButton?.expanded, !!headerContentVisible]);
125126

126127
const onToggleHeaderButtonClick = (e) => {
127128
onToggleHeaderContentVisibility(enrichEventWithDetails(e, { visible: !headerContentVisible }));
@@ -131,7 +132,7 @@ const ObjectPageAnchorBar = forwardRef<HTMLElement, ObjectPageAnchorBarPropTypes
131132
<section
132133
data-component-name="ObjectPageAnchorBar"
133134
style={style}
134-
role={accessibilityAttributes?.objectPageAnchorBar?.role}
135+
role={accessibilityAttributes?.role}
135136
className={!hidePinButton ? classNames.container : null}
136137
ref={ref}
137138
>
@@ -149,7 +150,10 @@ const ObjectPageAnchorBar = forwardRef<HTMLElement, ObjectPageAnchorBarPropTypes
149150
onMouseOver={onHoverToggleButton}
150151
onMouseLeave={onHoverToggleButton}
151152
tooltip={i18nBundle.getText(!headerContentVisible ? EXPAND_HEADER : COLLAPSE_HEADER)}
152-
accessibleName={i18nBundle.getText(!headerContentVisible ? EXPAND_HEADER : COLLAPSE_HEADER)}
153+
accessibleName={
154+
accessibilityAttributes?.expandButton?.accessibleName ??
155+
i18nBundle.getText(!headerContentVisible ? EXPAND_HEADER : COLLAPSE_HEADER)
156+
}
153157
data-component-name="ObjectPageAnchorBarExpandBtn"
154158
/>
155159
{shouldRenderHeaderPinnableButton && (

tsconfig.spec.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"compilerOptions": {
33
"target": "ES2021",
44
"lib": ["es2022", "dom"],
5-
"types": ["cypress", "node", "@testing-library/cypress", "cypress-real-events"],
5+
"types": ["cypress", "node", "@testing-library/cypress", "cypress-real-events", "chai"],
66
"moduleResolution": "Node",
77
"jsx": "react-jsx",
88
"composite": true

0 commit comments

Comments
 (0)