Skip to content

fix(ObjectPage): announce first section heading with screen readers #7186

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 7, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions packages/main/src/components/ObjectPage/ObjectPage.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,7 @@ describe('ObjectPage', () => {
cy.get('[data-component-name="ObjectPageAnchorBarExpandBtn"]').click();
cy.findByText('https://github.com/SAP/ui5-webcomponents-react').should('not.be.visible');
});

it('ObjectPageSection/SubSection: Custom header & hideTitleText', () => {
document.body.style.margin = '0px';
const TestComp = ({ mode }: ObjectPagePropTypes) => {
Expand Down Expand Up @@ -841,8 +842,12 @@ describe('ObjectPage', () => {
cy.get('[ui5-tabcontainer]').findUi5TabByText('Goals').click();
cy.findByText('Custom Header Section One').should('be.visible');
cy.findByText('toggle titleText1').click({ scrollBehavior: false, force: true });
// first titleText should never be displayed
cy.findByText('Goals').should('not.be.visible');
// first titleText should never be displayed (not.be.visible doesn't work here - only invisible for sighted users)
cy.findByText('Goals')
.parent()
.should('have.css', 'width', '1px')
.and('have.css', 'margin', '-1px')
.and('have.css', 'position', 'absolute');
cy.findByText('Custom Header Section One').should('be.visible');

cy.get('[ui5-tabcontainer]').findUi5TabByText('Personal').click();
Expand Down
19 changes: 11 additions & 8 deletions packages/main/src/components/ObjectPage/ObjectPage.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,18 @@
&[data-in-iframe='true'] {
scroll-behavior: auto;
}
section[id*='ObjectPageSection-'] > div[role='heading'] {
display: none;
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const meta = {
),
titleArea: (
<ObjectPageTitle
header="Denise Smith"
header={<Title level="H2">Denise Smith</Title>}
subHeader="Senior UI Developer"
actionsBar={
<Toolbar design="Transparent">
Expand Down
4 changes: 3 additions & 1 deletion packages/main/src/components/ObjectPageTitle/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ export interface ObjectPageTitlePropTypes extends CommonProps {

/**
* The `header` is positioned in the `ObjectPageTitle` left area.
*
* Use this prop to display a `Title` (or any other component that serves as a heading).
*/
header?: ReactNode;
/**
* The `subHeader` is positioned in the `ObjectPageTitle` left area below the `header`.
*
* Use this aggregation to display a component like `Label` or any other component that serves as sub header.
*/
subHeader?: ReactNode;
Expand Down Expand Up @@ -225,7 +227,7 @@ const ObjectPageTitle = forwardRef<HTMLDivElement, ObjectPageTitlePropTypes>((pr
>
<FlexBox className={classNames.titleMainSection} onClick={onHeaderClick}>
{header && (
<div className={classNames.title} data-component-name="ObjectPageTitleHeader" /*onClick={onHeaderClick}*/>
<div className={classNames.title} data-component-name="ObjectPageTitleHeader">
{header}
</div>
)}
Expand Down
Loading