Skip to content
This repository has been archived by the owner on May 24, 2024. It is now read-only.

Commit

Permalink
[terra-section-header] Allow sticky header title (#4037)
Browse files Browse the repository at this point in the history
Co-authored-by: Sugan G <Sugan.G@cerner.com>
  • Loading branch information
sugan2416 and Sugan G authored Feb 23, 2024
1 parent f6e211c commit eace3f7
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 1 deletion.
3 changes: 3 additions & 0 deletions packages/terra-core-docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

* Added
* Added test to `terra-section-header` for the sticky section header title.

## 1.58.0 - (February 20, 2024)

* Changed
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* eslint-disable react/forbid-dom-props */
import React from 'react';
import SectionHeader from 'terra-section-header';

export default () => (
<div style={{
width: '400px', height: '200px', background: 'gray', margin: '10px', overflow: 'scroll',
}}
>
<div style={{ width: '600px', height: '400px' }}>
<SectionHeader
text="Closed Section Header 1"
isTitleSticky
onClick={() => {}}
/>
<br />
<SectionHeader
text="Closed Section Header 2"
isTitleSticky
onClick={() => {}}
/>
<br />
<SectionHeader
text="Section Header 3"
isTitleSticky
/>
</div>
</div>
);
3 changes: 3 additions & 0 deletions packages/terra-section-header/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

* Changed
* Allow the title of the `terra-section-header` to be sticky.

## 2.66.0 - (February 15, 2024)

* Changed
Expand Down
2 changes: 1 addition & 1 deletion packages/terra-section-header/src/SectionHeader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ class SectionHeader extends React.Component {

return (
<Element {...headerAttributes} className={sectionHeaderClassNames} aria-label={!onClick ? headerText : undefined}>
<ArrangeWrapper {...buttonAttributes} className={cx('arrange-wrapper', { 'title-fixed': isTitleFixed })}>
<ArrangeWrapper {...buttonAttributes} className={cx('arrange-wrapper', { 'title-fixed': isTitleFixed, 'title-sticky': headerAttributes.isTitleSticky })}>
<Arrange
fitStart={onClick && accordionIcon}
fill={<span aria-hidden={(onClick !== undefined)} className={cx('title')}>{headerText}</span>}
Expand Down
7 changes: 7 additions & 0 deletions packages/terra-section-header/src/SectionHeader.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -156,5 +156,12 @@
&.title-fixed {
position: absolute;
}

// Make the section header title sticky
&.title-sticky {
position: sticky;
left: 12px;
width: auto;
}
}
}
13 changes: 13 additions & 0 deletions packages/terra-section-header/tests/jest/SectionHeader.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,17 @@ describe('SectionHeader', () => {
const sectionHeader = wrapper.find('.arrange-wrapper.title-fixed').at(0);
expect(sectionHeader).toHaveLength(1);
});

it('verifies that section header with a sticky title has appropriate classes', () => {
const wrapper = enzyme.shallow(
<SectionHeader
text="foo"
level={2}
isTitleSticky
/>,
);

const sectionHeader = wrapper.find('.arrange-wrapper.title-sticky').at(0);
expect(sectionHeader).toHaveLength(1);
});
});

0 comments on commit eace3f7

Please sign in to comment.