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

Rework table height to support percentages again #13683

Merged
merged 5 commits into from
May 17, 2024

Conversation

aptkingston
Copy link
Member

@aptkingston aptkingston commented May 14, 2024

Description

Recent changes to the table component meant that using percentages as a height no longer worked. This was because we were not apply height to the outer DOM node, but instead applying it to the inner grid component itself, breaking relativity to the parent of the table component as the user sees it. Those changes were motivated by a desire to ensure that the min height of the table is respected, ensuring users can't create a table that's too small to be used.

This PR reworks how height is calculated and applied so that percentages work again, but we also still use the correct min-height.

Example of a table with a height of 50%, showing the parent container to highlight that it's working:
image

Addresses

@@ -50,8 +51,7 @@
metadata: { dataSource: table },
},
]
$: height = $component.styles?.normal?.height || "408px"
$: styles = getSanitisedStyles($component.styles)
$: gridContext?.minHeight?.subscribe($height => (minHeight = $height))
Copy link
Member Author

Choose a reason for hiding this comment

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

The core grid is the source of truth and makes min height available in context, which we can consume from here and honour.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Does unsubscribe ever need to be called on this?

Would storing minHeight as reactive variable and then assigning it to minHeight work?

$: contextMinHeight = gridContext.minHeight;
$: minHeight = $contextMinHeight

Obviously more verbose, but if the unsubscribe is necessary might be worth it.

Very much NAB anyway.

Copy link
Member Author

Choose a reason for hiding this comment

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

I have a feeling svelte manages that automatically if called inside a reactive statement, but even if it doesn't then we don't need to worry since this will only every trigger once (when grid context is set for the first time) so we don't need to worry about excess subscriptions.

Good intuition though, because in other cases that could absolutely be a problem.

Copy link
Member Author

Choose a reason for hiding this comment

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

Going to move this into the onMount handler to be more explicit about the fact it'll only run once. Makes sense to be explicit about it.

Padding + SmallRowHeight + $rowHeight + (showControls ? ControlsHeight : 0)

// Derive min height and make available in context
const minHeight = derived(rowHeight, $height => {
Copy link
Member Author

Choose a reason for hiding this comment

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

Small change to make this a derived store rather than a primitive, so it's observable.

Copy link
Contributor

@deanhannigan deanhannigan left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Collaborator

@Ghrehh Ghrehh left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -50,8 +51,7 @@
metadata: { dataSource: table },
},
]
$: height = $component.styles?.normal?.height || "408px"
$: styles = getSanitisedStyles($component.styles)
$: gridContext?.minHeight?.subscribe($height => (minHeight = $height))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does unsubscribe ever need to be called on this?

Would storing minHeight as reactive variable and then assigning it to minHeight work?

$: contextMinHeight = gridContext.minHeight;
$: minHeight = $contextMinHeight

Obviously more verbose, but if the unsubscribe is necessary might be worth it.

Very much NAB anyway.

@aptkingston aptkingston merged commit a705fbd into master May 17, 2024
10 checks passed
@aptkingston aptkingston deleted the rework-grid-block-height branch May 17, 2024 09:55
@github-actions github-actions bot locked and limited conversation to collaborators May 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants