Skip to content

Commit

Permalink
Signup: fix the title overflow of the classic signup flows. (#95426)
Browse files Browse the repository at this point in the history
* Implement the functionality of disabling the prevent widows
functionality of <FormattedHeader>

* Disable preventing widows of <FormattedHeader> and set `text-wrap` as
`pretty` for the classic sign-up flows
  • Loading branch information
southp authored Oct 17, 2024
1 parent 5495065 commit e3b0492
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions client/components/formatted-header/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ function render() {
- `subHeaderText` (`node`) - Sub header text (optional)
- `compactOnMobile` (`bool`) - Display a compact header on small screens (optional)
- `isSecondary` (`bool`) - Use the H2 element instead of the H1 (optional)
- `disablePreventWidows` (`bool`) - Disable the default behavior of inserting non-breaking space to prevent dangling words.
17 changes: 11 additions & 6 deletions client/components/formatted-header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ interface Props extends PropsWithChildren {
subHeaderAs?: ElementType;
subHeaderText?: ReactNode;
tooltipText?: ReactNode;
disablePreventWidows?: boolean;
}

const FormattedHeader: FC< Props > = ( {
Expand All @@ -35,6 +36,7 @@ const FormattedHeader: FC< Props > = ( {
subHeaderAs: SubHeaderAs = 'p',
subHeaderText,
tooltipText,
disablePreventWidows,
} ) => {
const classes = clsx( 'formatted-header', className, {
'is-without-subhead': ! subHeaderText,
Expand All @@ -54,24 +56,27 @@ const FormattedHeader: FC< Props > = ( {
</InfoPopover>
);

const formattedHeaderText = disablePreventWidows ? headerText : preventWidows( headerText, 2 );
const formattedSubHeaderText = disablePreventWidows
? subHeaderText
: preventWidows( subHeaderText, 2 );

return (
<header id={ id } className={ classes }>
<div>
{ ! isSecondary && (
<h1 className={ headerClasses }>
{ preventWidows( headerText, 2 ) } { tooltip }
{ formattedHeaderText } { tooltip }
</h1>
) }
{ isSecondary && (
<h2 className={ headerClasses }>
{ preventWidows( headerText, 2 ) } { tooltip }
{ formattedHeaderText } { tooltip }
</h2>
) }
{ screenReader && <h2 className="screen-reader-text">{ screenReader }</h2> }
{ subHeaderText && (
<SubHeaderAs className={ subtitleClasses }>
{ preventWidows( subHeaderText, 2 ) }
</SubHeaderAs>
{ formattedSubHeaderText && (
<SubHeaderAs className={ subtitleClasses }>{ formattedSubHeaderText }</SubHeaderAs>
) }
</div>
{ children }
Expand Down
1 change: 1 addition & 0 deletions client/signup/step-wrapper/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ class StepWrapper extends Component {
headerText={ this.headerText() }
subHeaderText={ this.subHeaderText() }
align={ align }
disablePreventWidows
/>
{ headerImageUrl && (
<div className="step-wrapper__header-image">
Expand Down
1 change: 1 addition & 0 deletions client/signup/step-wrapper/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

.formatted-header {
flex-grow: 1;
text-wrap: pretty;
}

@include breakpoint-deprecated( "<660px" ) {
Expand Down

0 comments on commit e3b0492

Please sign in to comment.