Skip to content

Commit 8c49573

Browse files
authored
fix(ObjectPage): announce first section heading with screen readers (#7186)
Fixes #7043
1 parent e99a24f commit 8c49573

File tree

4 files changed

+26
-16
lines changed

4 files changed

+26
-16
lines changed

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,12 @@ describe('ObjectPage', () => {
355355

356356
cy.wait(200);
357357

358-
cy.findByText('Goals').should('not.be.visible');
358+
// first titleText should never be displayed (not.be.visible doesn't work here - only invisible for sighted users)
359+
cy.findByText('Goals')
360+
.parent()
361+
.should('have.css', 'width', '1px')
362+
.and('have.css', 'margin', '-1px')
363+
.and('have.css', 'position', 'absolute');
359364
cy.findByText('Employment').should('not.be.visible');
360365
cy.findByText('Test').should('be.visible');
361366

@@ -819,6 +824,7 @@ describe('ObjectPage', () => {
819824
cy.get('[data-component-name="ObjectPageAnchorBarExpandBtn"]').click();
820825
cy.findByText('https://github.com/SAP/ui5-webcomponents-react').should('not.be.visible');
821826
});
827+
822828
it('ObjectPageSection/SubSection: Custom header & hideTitleText', () => {
823829
document.body.style.margin = '0px';
824830
const TestComp = ({ mode }: ObjectPagePropTypes) => {
@@ -880,8 +886,12 @@ describe('ObjectPage', () => {
880886
cy.get('[ui5-tabcontainer]').findUi5TabByText('Goals').click();
881887
cy.findByText('Custom Header Section One').should('be.visible');
882888
cy.findByText('toggle titleText1').click({ scrollBehavior: false, force: true });
883-
// first titleText should never be displayed
884-
cy.findByText('Goals').should('not.be.visible');
889+
// first titleText should never be displayed (not.be.visible doesn't work here - only invisible for sighted users)
890+
cy.findByText('Goals')
891+
.parent()
892+
.should('have.css', 'width', '1px')
893+
.and('have.css', 'margin', '-1px')
894+
.and('have.css', 'position', 'absolute');
885895
cy.findByText('Custom Header Section One').should('be.visible');
886896

887897
cy.get('[ui5-tabcontainer]').findUi5TabByText('Personal').click();

packages/main/src/components/ObjectPage/ObjectPage.module.css

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,18 @@
2121
&[data-in-iframe='true'] {
2222
scroll-behavior: auto;
2323
}
24-
section[id*='ObjectPageSection-'] > div[role='heading'] {
25-
display: none;
26-
}
2724

28-
/* explanation why first-child selector is not sufficient here:
29-
https://stackoverflow.com/questions/7128406/css-select-the-first-child-from-elements-with-particular-attribute
30-
*/
31-
section[id*='ObjectPageSection-'] ~ section[id*='ObjectPageSection-'] > div[role='heading'] {
32-
display: block;
25+
/*invisible first heading*/
26+
section[id*='ObjectPageSection-']:first-of-type > div[role='heading'] {
27+
position: absolute;
28+
width: 1px;
29+
height: 1px;
30+
padding: 0;
31+
margin: -1px;
32+
overflow: hidden;
33+
clip: rect(0, 0, 0, 0);
34+
border: 0;
35+
white-space: nowrap;
3336
}
3437
}
3538

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ const meta = {
7272
),
7373
titleArea: (
7474
<ObjectPageTitle
75-
header="Denise Smith"
75+
header={<Title level="H2">Denise Smith</Title>}
7676
subHeader="Senior UI Developer"
7777
actionsBar={
7878
<Toolbar design="Transparent">

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,7 @@ const ObjectPageTitle = forwardRef<HTMLDivElement, ObjectPageTitlePropTypes>((pr
158158
>
159159
<FlexBox className={classNames.titleMainSection} onClick={onHeaderClick}>
160160
{header && (
161-
<div
162-
className={classNames.title}
163-
data-component-name="ObjectPageTitleHeader" /*onClick={onHeaderClick}*/
164-
>
161+
<div className={classNames.title} data-component-name="ObjectPageTitleHeader">
165162
{header}
166163
</div>
167164
)}

0 commit comments

Comments
 (0)