Skip to content

Commit 050874c

Browse files
committed
fix(pie-button): DSW-3684 apply width 100% to host when isFullWidth is set
1 parent 167317c commit 050874c

File tree

9 files changed

+93
-2
lines changed

9 files changed

+93
-2
lines changed

.changeset/empty-pots-collect.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"@justeattakeaway/pie-button": patch
3+
"@justeattakeaway/pie-cookie-banner": patch
4+
"@justeattakeaway/pie-modal": patch
5+
"@justeattakeaway/pie-notification": patch
6+
---
7+
8+
[Fixed] - Applied `width: 100%` to the `pie-button` host element when `isFullWidth` is set, ensuring buttons span full width in flex, grid, and block layouts. Updated `pie-cookie-banner`, `pie-modal`, and `pie-notification` to reset button width on desktop.

apps/pie-storybook/stories/pie-modal.stories.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ const modalStoryMeta: ModalStoryMeta = {
5858
control: 'boolean',
5959
},
6060
hasStackedActions: {
61+
description: 'When true, the actions will expand to full width and stack vertically. Only available below the mid breakpoint.',
6162
control: 'boolean',
6263
},
6364
isHeadingEmphasised: {

apps/pie-storybook/stories/testing/pie-button.test.stories.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
type ButtonProps as ButtonPropsBase, defaultProps, iconPlacements, responsiveSizes, sizes, types, variants,
88
} from '@justeattakeaway/pie-webc/components/button';
99
import '@justeattakeaway/pie-icons-webc/dist/IconPlusCircle.js';
10+
import '@justeattakeaway/pie-css/dist/helpers/typography.css';
1011

1112
import {
1213
createStory, createVariantStory, type TemplateFunction, sanitizeAndRenderHTML,
@@ -496,3 +497,55 @@ export const DestructiveGhostVariations = createVariantStory<ButtonProps>(Templa
496497
...sharedPropMatrix,
497498
variant: ['destructive-ghost'],
498499
}, { multiColumn: true });
500+
501+
const IsFullWidthLayoutTemplate: TemplateFunction<ButtonProps> = () => html`
502+
<style>
503+
.layout-container {
504+
margin-block-end: var(--dt-spacing-d);
505+
padding: var(--dt-spacing-b);
506+
border: 1px solid var(--dt-color-border-default);
507+
}
508+
.layout-label {
509+
margin-block-end: var(--dt-spacing-b);
510+
}
511+
.flex-container {
512+
display: flex;
513+
}
514+
.grid-container {
515+
display: grid;
516+
}
517+
.block-container {
518+
display: block;
519+
}
520+
</style>
521+
522+
<div class="layout-container">
523+
<p class="layout-label u-font-body-strong-l">Flex container (display: flex)</p>
524+
<div class="flex-container">
525+
<pie-button isFullWidth data-test-id="pie-button-flex">Full Width in Flex</pie-button>
526+
</div>
527+
</div>
528+
529+
<div class="layout-container">
530+
<p class="layout-label u-font-body-strong-l">Grid container (display: grid)</p>
531+
<div class="grid-container">
532+
<pie-button isFullWidth data-test-id="pie-button-grid">Full Width in Grid</pie-button>
533+
</div>
534+
</div>
535+
536+
<div class="layout-container">
537+
<p class="layout-label u-font-body-strong-l">Block container (display: block)</p>
538+
<div class="block-container">
539+
<pie-button isFullWidth data-test-id="pie-button-block">Full Width in Block</pie-button>
540+
</div>
541+
</div>
542+
543+
<div class="layout-container">
544+
<p class="layout-label u-font-body-strong-l">Flex container without isFullWidth (for comparison)</p>
545+
<div class="flex-container">
546+
<pie-button data-test-id="pie-button-flex-no-fullwidth">Without Full Width in Flex</pie-button>
547+
</div>
548+
</div>
549+
`;
550+
551+
export const IsFullWidthLayoutVariations = createStory<ButtonProps>(IsFullWidthLayoutTemplate, defaultArgs)();

apps/pie-storybook/stories/testing/pie-modal.test.stories.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ const modalStoryMeta: ModalStoryMeta = {
5252
control: 'boolean',
5353
},
5454
hasStackedActions: {
55+
description: 'When true, the actions will expand to full width and stack vertically. Only available below the mid breakpoint.',
5556
control: 'boolean',
5657
},
5758
isHeadingEmphasised: {

packages/components/pie-button/src/button.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ $prefix: 'o-btn';
1010

1111
:host([isfullwidth]) {
1212
display: block;
13+
width: 100%;
1314
}
1415

1516
// Base button styles

packages/components/pie-button/test/visual/pie-button.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,14 @@ variants.forEach((variant) => {
1616
await percySnapshot(page, `PIE Button - Variant: ${variant}`, { widths: [1280] });
1717
});
1818
});
19+
20+
test('should render isFullWidth correctly in different layout contexts', async ({ page }) => {
21+
// Arrange
22+
const buttonPage = new BasePage(page, 'button--is-full-width-layout-variations');
23+
const buttonComponent = new ButtonComponent(page);
24+
await buttonPage.load();
25+
26+
// Assert
27+
await expect.soft(buttonComponent.componentLocator.first()).toBeVisible();
28+
await percySnapshot(page, 'PIE Button - isFullWidth in different layouts', { widths: [1280] });
29+
});

packages/components/pie-cookie-banner/src/cookie-banner.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ $breakpoint-wide: 700px;
125125

126126
justify-content: flex-start;
127127
align-items: center;
128+
129+
> pie-button {
130+
width: auto;
131+
}
128132
}
129133
}
130134

packages/components/pie-modal/src/modal.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,12 @@
257257
@include media('<md') {
258258
flex-direction: column;
259259
}
260+
261+
@include media('>=md') {
262+
> pie-button {
263+
width: auto;
264+
}
265+
}
260266
}
261267
}
262268

packages/components/pie-notification/src/notification.scss

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,16 @@
119119
margin-inline-start: auto;
120120
}
121121

122-
@include media('<md') {
123-
&.c-notification-footer--stacked {
122+
&.c-notification-footer--stacked {
123+
@include media('<md') {
124124
flex-direction: column-reverse;
125125
}
126+
127+
@include media('>=md') {
128+
> pie-button {
129+
width: auto;
130+
}
131+
}
126132
}
127133
}
128134
}

0 commit comments

Comments
 (0)