Skip to content

Commit df044be

Browse files
FrontendlandCopilot
andcommitted
💄 Fix ExpandableTable button alignment in flex containers
Co-authored-by: Copilot <copilot@github.com>
1 parent 6149b0d commit df044be

3 files changed

Lines changed: 82 additions & 69 deletions

File tree

src/blocks/ExpandableTable/ExpandableTable.astro

Lines changed: 44 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
---
2+
import { ConditionalWrapper } from 'webcoreui/astro'
3+
24
import Button from '@blocks/Button/Button.astro'
35
46
import type { ExpandableTableProps } from './expandableTable'
@@ -32,45 +34,49 @@ const classes = [
3234
]
3335
---
3436

35-
<div
36-
class:list={classes}
37-
style={maxHeight ? `max-height:${maxHeight}` : undefined}
38-
>
39-
<table>
40-
{headings?.length && (
41-
<thead>
42-
<tr>
43-
{headings.map(heading => (
44-
<th>{heading}</th>
45-
))}
46-
</tr>
47-
</thead>
48-
)}
49-
<tbody>
50-
{data.map((row, index) => (
51-
<tr
52-
data-hidden={numberOfVisibleRows < index + 1 ? 'true' : undefined}
53-
>
54-
{row.map(column => (
55-
<td>
56-
<Fragment set:html={column} />
57-
</td>
58-
))}
59-
</tr>
60-
))}
61-
</tbody>
62-
</table>
63-
</div>
37+
<ConditionalWrapper condition={data.length > numberOfVisibleRows}>
38+
<div slot="wrapper">children</div>
39+
40+
<div
41+
class:list={classes}
42+
style={maxHeight ? `max-height:${maxHeight}` : undefined}
43+
>
44+
<table>
45+
{headings?.length && (
46+
<thead>
47+
<tr>
48+
{headings.map(heading => (
49+
<th>{heading}</th>
50+
))}
51+
</tr>
52+
</thead>
53+
)}
54+
<tbody>
55+
{data.map((row, index) => (
56+
<tr
57+
data-hidden={numberOfVisibleRows < index + 1 ? 'true' : undefined}
58+
>
59+
{row.map(column => (
60+
<td>
61+
<Fragment set:html={column} />
62+
</td>
63+
))}
64+
</tr>
65+
))}
66+
</tbody>
67+
</table>
68+
</div>
6469

65-
{data.length > numberOfVisibleRows && (
66-
<Button
67-
data-id="w-expander"
68-
data-expand-label={expandButtonLabel}
69-
data-collapse-label={collapseButtonLabel}
70-
text={expandButtonLabel}
71-
{...expandButton}
72-
/>
73-
)}
70+
{data.length > numberOfVisibleRows && (
71+
<Button
72+
data-id="w-expander"
73+
data-expand-label={expandButtonLabel}
74+
data-collapse-label={collapseButtonLabel}
75+
text={expandButtonLabel}
76+
{...expandButton}
77+
/>
78+
)}
79+
</ConditionalWrapper>
7480

7581
<script>
7682
import { on } from 'webcoreui'
Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<script lang="ts">
22
import { classNames } from 'webcoreui'
3+
import { ConditionalWrapper } from 'webcoreui/svelte'
34
45
import Button from '@blocks/Button/Button.svelte'
56
@@ -36,33 +37,35 @@
3637
const toggle = () => expanded = !expanded
3738
</script>
3839

39-
<div class={classes} style={maxHeight ? `max-height:${maxHeight}` : null}>
40-
<table>
41-
{#if headings?.length}
42-
<thead>
43-
<tr>
44-
{#each headings as heading}
45-
<th>{heading}</th>
46-
{/each}
47-
</tr>
48-
</thead>
49-
{/if}
50-
<tbody>
51-
{#each data as row, index}
52-
<tr data-hidden={numberOfVisibleRows < index + 1 && !expanded ? 'true' : undefined}>
53-
{#each row as column}
54-
<td>{@html column}</td>
55-
{/each}
56-
</tr>
57-
{/each}
58-
</tbody>
59-
</table>
60-
</div>
40+
<ConditionalWrapper condition={data.length > numberOfVisibleRows}>
41+
<div class={classes} style={maxHeight ? `max-height:${maxHeight}` : null}>
42+
<table>
43+
{#if headings?.length}
44+
<thead>
45+
<tr>
46+
{#each headings as heading}
47+
<th>{heading}</th>
48+
{/each}
49+
</tr>
50+
</thead>
51+
{/if}
52+
<tbody>
53+
{#each data as row, index}
54+
<tr data-hidden={numberOfVisibleRows < index + 1 && !expanded ? 'true' : undefined}>
55+
{#each row as column}
56+
<td>{@html column}</td>
57+
{/each}
58+
</tr>
59+
{/each}
60+
</tbody>
61+
</table>
62+
</div>
6163

62-
{#if data.length > numberOfVisibleRows}
63-
<Button
64-
text={expanded ? collapseButtonLabel : expandButtonLabel}
65-
onClick={toggle}
66-
{...expandButton}
67-
/>
68-
{/if}
64+
{#if data.length > numberOfVisibleRows}
65+
<Button
66+
text={expanded ? collapseButtonLabel : expandButtonLabel}
67+
onClick={toggle}
68+
{...expandButton}
69+
/>
70+
{/if}
71+
</ConditionalWrapper>

src/blocks/ExpandableTable/ExpandableTable.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React, { useState } from 'react'
22
import { classNames } from 'webcoreui'
3+
import { ConditionalWrapper } from 'webcoreui/react'
34

45
import Button from '@blocks/Button/Button.tsx'
56

@@ -43,7 +44,10 @@ const ExpandableTable = ({
4344
}
4445

4546
return (
46-
<React.Fragment>
47+
<ConditionalWrapper
48+
condition={data.length > numberOfVisibleRows}
49+
wrapper={children => <div>{children}</div>}
50+
>
4751
<div className={classes} style={styleVariables}>
4852
<table>
4953
{headings?.length && (
@@ -80,7 +84,7 @@ const ExpandableTable = ({
8084
{...expandButton}
8185
/>
8286
)}
83-
</React.Fragment>
87+
</ConditionalWrapper>
8488
)
8589
}
8690

0 commit comments

Comments
 (0)