8000 [MWPW-171327] Table sticky heading by DKos95 · Pull Request #4054 · adobecom/milo · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[MWPW-171327] Table sticky heading #4054

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

Merged
merged 11 commits into from
May 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions libs/blocks/table/table.css
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,11 @@
transition: box-shadow 200ms cubic-bezier(0.33, 1, 0.68, 1);
}

.table.cancel-sticky .row-heading,
.table.cancel-sticky .row-highlight {
position: static;
}

.table:not(.merch) .row-heading.active,
.table.merch .row-heading.active .col-heading {
transition-duration: 400ms;
Expand Down
7 changes: 7 additions & 0 deletions libs/blocks/table/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,11 @@ function applyStylesBasedOnScreenSize(table, originTable) {
setRowStyle();
}

function handleStickyHeader(el) {
if (!el.classList.value.includes('sticky')) return;
setTimeout(() => el.classList.toggle('cancel-sticky', !(el.querySelector('.row-heading').offsetHeight / window.innerHeight < 0.45)));
}

export default function init(el) {
el.setAttribute('role', 'table');
if (el.parentElement.classList.contains('section')) {
Expand Down Expand Up @@ -657,10 +662,12 @@ export default function init(el) {
setTooltipPosition(el);
};
handleResize();
handleStickyHeader(el);

let deviceBySize = defineDeviceByScreenSize();
window.addEventListener('resize', () => {
debounce(handleEqualHeight(el, '.row-heading'), 300);
handleStickyHeader(el);
if (deviceBySize === defineDeviceByScreenSize()) return;
deviceBySize = defineDeviceByScreenSize();
handleResize();
Expand Down
14 changes: 10 additions & 4 deletions nala/blocks/table/table.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,12 @@ test.describe('Milo Table block feature test suite', () => {
// verify table header row attributes ( class, position(sticky) and top )
await expect(await table.stickyTable).toBeVisible();

if (!await table.stickyTable.evaluate((el) => el.classList.contains('cancel-sticky'))) {
await expect(await table.stickyRow).toHaveCSS('position', 'sticky');
await expect(await table.stickyRow).toHaveCSS('top', '64px');
}

await expect(await table.stickyRow).toHaveAttribute('class', 'row row-1 row-heading top-border-transparent');
await expect(await table.stickyRow).toHaveCSS('position', 'sticky');
await expect(await table.stickyRow).toHaveCSS('top', '64px');

// verify table row, column count
await expect(await table.rows).toHaveCount(data.rowsCount);
Expand Down Expand Up @@ -111,8 +114,11 @@ test.describe('Milo Table block feature test suite', () => {
await expect(await table.collapseStickyTable).toBeVisible();
await expect(table.highlightRow).toHaveClass(/row.*row-1.*row-highlight/);
await expect(table.stickyRow).toHaveClass(/row.*row-2.*row-heading/);
await expect(await table.stickyRow).toHaveCSS('position', 'sticky');
await expect(await table.stickyRow).toHaveCSS('top', '114px');

if (!await table.collapseStickyTable.evaluate((el) => el.classList.contains('cancel-sticky'))) {
await expect(await table.stickyRow).toHaveCSS('position', 'sticky');
await expect(await table.stickyRow).toHaveCSS('top', '114px');
}

// verify table rows and columns count
await expect(await table.rows).toHaveCount(data.rowsCount);
Expand Down
Loading
0