Skip to content

Commit

Permalink
fix(sbb-container): fix background color for nested containers (#2611)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeripeierSBB authored Apr 24, 2024
1 parent 38b88e1 commit c9f0e0e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
9 changes: 8 additions & 1 deletion src/components/container/container/container.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@
}

.sbb-container {
background-color: var(--sbb-container-background-color, transparent);
background-color: var(--sbb-container-background-color);

// In order to support nested sbb-containers (e.g. if used in an overlay), we need to explicitly set background color to transparent.
// We cannot use the --sbb-container-background-color variable because using it would
// destroy sbb-sticky-bar behavior when the container and the sticky bar have transparent color.
:host([color='transparent']) & {
background-color: transparent;
}

// Placing content before and after the container stops the margin of inner elements from overflowing
&::after,
Expand Down
23 changes: 21 additions & 2 deletions src/components/container/container/container.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,25 @@ const defaultArgs: Args = {
color: color.options![0],
};

const DefaultTemplate = ({ color, ...args }: Args): TemplateResult => html`
<sbb-container ${sbbSpread(args)} color=${color}>
const DefaultTemplate = (args: Args): TemplateResult => html`
<sbb-container ${sbbSpread(args)}>
${containerContent('Example title')} ${containerContent('Another one')}
${containerContent('And another one', true)}
</sbb-container>
`;

// Only for visual regression
const NestedContainerTemplate = (): TemplateResult => html`
<sbb-container color="white">
${containerContent('Example title')}
<div style="background-color: var(--sbb-color-milk);">
<sbb-container color="transparent">
${containerContent('And another one', true)}
</sbb-container>
</div>
</sbb-container>
`;

export const Default: StoryObj = {
render: DefaultTemplate,
argTypes: defaultArgTypes,
Expand All @@ -78,7 +90,14 @@ export const Expanded: StoryObj = {
args: { ...defaultArgs, expanded: true },
};

export const NestedContainer: StoryObj = {
render: NestedContainerTemplate,
argTypes: { defaultArgTypes },
args: { ...defaultArgs, expanded: true },
};

const meta: Meta = {
excludeStories: /^(NestedContainer)$/,
parameters: {
docs: {
extractComponentDescription: () => readme,
Expand Down

0 comments on commit c9f0e0e

Please sign in to comment.