Skip to content
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

[IRN-5018][BpkNavigationBar][BpkBottomSheet] Add handling for long title text #3393

Merged
merged 10 commits into from May 2, 2024

Conversation

steviehailey-skyscanner
Copy link
Contributor

@steviehailey-skyscanner steviehailey-skyscanner commented Apr 29, 2024

It was discovered that long titles overlap the buttons on the BpkBottomSheet component. The issue arises from the underlying BpkNavigationBar component lacking handling for this scenario.
Fix improves layout based on design requirement to clamp the text with ellipsis when there is not enough space to fit without encroaching on buttons or wrapping to an additional line.

Screenshots

Issue of long heading overlapping buttons

image

Design guidance on expected layout

image

Examples after fix

  • Navigation Bar
  • BottomSheet
Tablet Large Mobile Small Mobile

Other selected cases - Small Mobile

Action Button No Title Graphic Logo Header

Remember to include the following changes:

  • Ensure the PR title includes the name of the component you are changing so it's clear in the release notes for consumers of the changes in the version e.g [KOA-123][BpkButton] Updating the colour
  • README.md (If you have created a new component)
  • Component README.md
  • Tests
  • Storybook examples created/updated
  • Type declaration (.d.ts) files updated
  • For breaking changes or deprecating components/properties, migration guides added to the description of the PR. If the guide has large changes, consider creating a new Markdown page inside the component's docs folder and link it here

Copy link

Visit https://backpack.github.io/storybook-prs/3393 to see this build running in a browser.

@@ -178,6 +178,26 @@ const OverflowingExample = () => (
</BottomSheetContainer>
);

const WrapHeaderTextExample = () => (
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Demo the issue
image

</BottomSheetContainer>
);

const WrapHeaderTextWithActionButtonExample = () => (
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Demo issue with Action button
image

Copy link

Visit https://backpack.github.io/storybook-prs/3393 to see this build running in a browser.

Copy link

github-actions bot commented Apr 29, 2024

Browser support

If this is a visual change, make sure you've tested it in multiple browsers.

Generated by 🚫 dangerJS against 7945dd8

Copy link

Visit https://backpack.github.io/storybook-prs/3393 to see this build running in a browser.

2 similar comments
Copy link

Visit https://backpack.github.io/storybook-prs/3393 to see this build running in a browser.

Copy link

Visit https://backpack.github.io/storybook-prs/3393 to see this build running in a browser.

@@ -178,6 +178,26 @@ const OverflowingExample = () => (
</BottomSheetContainer>
);

const LongHeaderTextExample = () => (
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Demo of misbehaving header at Bottom Sheet level - now fixed

@@ -59,6 +59,29 @@ const DefaultExample = () => (
</div>
);

const LongTitleTextExample = () => (
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Demo of misbehaving header at Nav Bar level - now fixed and inherited by Bottom Sheet

@@ -30,8 +30,6 @@
animation-timing-function: ease-in-out;
}

$close-button-width: tokens.bpk-spacing-lg() * 2;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was unused so removed

<BpkNavigationBar
id={headingId}
title={title &&
<BpkText id={headingId} textStyle={TEXT_STYLES.label1} tagName="h2">{title}</BpkText>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can now just pass the text and options for which element and style we want (which lets the component perform the text overflow for us)

@@ -23,12 +23,19 @@

.bpk-navigation-bar {
position: relative;
display: flex;
display: grid;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Attempted to layout with flex after removing some absolute positioning on the buttons but the desired spacing and handing of buttons being optional for different scenarios goes beyond what we can easily do with Flexbox. Grid can easily achieve the different cases we need.

padding: tokens.bpk-spacing-base();
flex-direction: row;
justify-content: center;
padding: tokens.bpk-spacing-lg();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Margin adjustments based on new design requirements

@@ -41,40 +48,45 @@
}

&__title {
grid-column: 2;
text-align: center;
text-overflow: ellipsis;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clamp the text for small screen/long title scenarios

@include utils.bpk-themeable-property(
color,
--bpk-navigation-bar-title-color,
tokens.$bpk-text-primary-day
);

// ensure we still apply ellipsis overflow when a custom title element is specified e.g. h2
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BottomSheet is an example where we want an h2 element but it needs to be treated as inline to clamp the text

&__leading-item,
&__trailing-item {
position: absolute;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This positioning was causing overlapping text and buttons

@@ -34,6 +36,8 @@ export type BarStyle = (typeof BAR_STYLES)[keyof typeof BAR_STYLES];
export type Props = {
id: string;
title: ReactNode;
titleTextStyle?: TextStyle;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make it easy for consumers to control the markup without needing to do their own title layout

>
{title}
</BpkText>
</span>
) : (
title
<div className={getClassNames('bpk-navigation-bar__title-container')}>{title}</div>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrapper to let us layout non-text elements for consumers e.g. graphic logo scenario

Copy link

Visit https://backpack.github.io/storybook-prs/3393 to see this build running in a browser.

1 similar comment
Copy link

github-actions bot commented May 1, 2024

Visit https://backpack.github.io/storybook-prs/3393 to see this build running in a browser.

Copy link

github-actions bot commented May 1, 2024

Visit https://backpack.github.io/storybook-prs/3393 to see this build running in a browser.

@@ -114,8 +112,13 @@ $close-button-width: tokens.bpk-spacing-lg() * 2;
position: sticky;
top: 0;
z-index: tokens.$bpk-zindex-tooltip - 1;
padding: tokens.bpk-spacing-sm() 0;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding additional padding to the heading based on BottomSheet design (avoiding adding to Nav Bar directly to avoid all other consumers gaining height)


@include borders.bpk-border-bottom-sm(tokens.$bpk-line-day);
@include utils.bpk-themeable-property(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid seeing scrolling content "through" the padding around the header
image

@steviehailey-skyscanner steviehailey-skyscanner added the minor Non breaking change label May 1, 2024
id={headingId}
title={title}
titleTextStyle={TEXT_STYLES.label1}
titleTagName={title ? "h2" : undefined}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we be passing in undefined or a better alternative value? Otherwise we could just do

Suggested change
titleTagName={title ? "h2" : undefined}
titleTagName={title && "h2"}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the title text can be an empty string, in which case we don't really want to output an empty h2 in case causes screen-reader confusion when navigating by heading. So, undefined here is equivalent to not providing a customised tagName if we don't have a title (maintaining previous behaviour of an empty span being generated instead). If we && we'll be asking for an "" element in that scenario which TS will object to.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am a bit confused with the response, so apologies.

Looking at the code for the NavBar if the title is empty then it wouldn't even render anything other than a div so there would always be something rendered anyway.

I am just thinking here it would be better if we passed something down even if a span to avoid using undefined as even with undefined BpkText will have a fallback anyway but it just might make sense to have somehting here so that we don't have to drill into BpkText to find out what happens if there is undefined passed down to it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, happy to be explicit about a span be the appropriate fallback here 👍

@@ -52,7 +52,7 @@ exports[`BpkBottomSheet renders correctly with action props 1`] = `
class="bpk-navigation-bar__title bpk-navigation-bar__title--default"
>
<span
class="bpk-text bpk-text--heading-5"
class="bpk-text bpk-text--label-1"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting these have now changed as this could lead me to believe these used to be wrong!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although since the span was empty it wouldn't have been a noticeable difference either way.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As these have changed have we checked this is still ok on the BpkModal?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the behaviour in terms of not clamping the text is consistent with before but it now respects the newer margins (and avoid overlapping the buttons) so long text will be slightly different than before

New (example from: https://backpack.github.io/storybook-prs/3393/?path=/story/bpk-component-modal--long-title)

image

Old (existing behaviour)

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this doesn't apply to the new Modal v2 which has it's own bespoke header
image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might wanna check with design if we are ok with the modal doing this in the case of these changes

Screenshot 2024-05-01 at 15 50 07

Taken from (accessory-modal)[https://backpack.github.io/storybook-prs/3393/?path=/story/bpk-component-modal--with-accessory-view]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spoke to design and they think this scenario is unrealistic and the handling is reasonable (certainly better than the existing behaviour) so no need to adjust any further
image

Comment on lines 57 to 58
titleTagName,
titleTextStyle,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you have made these optional, we will need to set these up as defaults otherwise it is going to cause issues when not provided.

That way you don't need to have what you have below and can just pass the props through.

Currently though there isn't even a fallback for titleTagName so that might cause some havoc

I would say here it probably should be

Suggested change
titleTagName,
titleTextStyle,
titleTagName = 'span',
titleTextStyle = TEXT_STYLES.heading5,

@steviehailey-skyscanner steviehailey-skyscanner changed the title Add example heading which doesn't wrap properly [IRN-5018][BpkNavigationBar][BpkBottomSheet] Add handling for long title text May 1, 2024
@@ -0,0 +1,35 @@
/*
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Auto-generated missing typedefs...

@@ -0,0 +1,41 @@
/*
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Auto-generated missing typedefs...

@@ -0,0 +1,39 @@
/*
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Auto-generated missing typedefs...

Copy link

github-actions bot commented May 1, 2024

Visit https://backpack.github.io/storybook-prs/3393 to see this build running in a browser.

Copy link

github-actions bot commented May 1, 2024

Visit https://backpack.github.io/storybook-prs/3393 to see this build running in a browser.

@olliecurtis olliecurtis marked this pull request as ready for review May 1, 2024 11:45
Copy link

github-actions bot commented May 1, 2024

Visit https://backpack.github.io/storybook-prs/3393 to see this build running in a browser.

@olliecurtis olliecurtis merged commit eb556ae into main May 2, 2024
9 checks passed
@olliecurtis olliecurtis deleted the IRN-5018 branch May 2, 2024 11:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
minor Non breaking change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants