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

Allow binding to Row's inner div #422

Merged
merged 1 commit into from
Jan 23, 2022
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
1 change: 1 addition & 0 deletions src/Row.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface RowProps
cols?: ColumnProps;
noGutters?: boolean;
form?: boolean;
inner?: HTMLElement;
}

export default class Row extends SvelteComponentTyped<
Expand Down
3 changes: 2 additions & 1 deletion src/Row.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
export let noGutters = false;
export let form = false;
export let cols = 0;
export let inner = undefined;

function getCols(cols) {
const colsValue = parseInt(cols);
Expand Down Expand Up @@ -37,6 +38,6 @@
);
</script>

<div {...$$restProps} class={classes}>
<div {...$$restProps} class={classes} bind:this={inner}>
<slot />
</div>
6 changes: 6 additions & 0 deletions src/__test__/Row.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,10 @@ describe('Row', () => {
const row = container.querySelector('.row');
expect(row.className).toBe('row row-cols-sm-2 row-cols-md-3');
});

test('should bind inner div', () => {
let inner;
const { container } = render(Row, { props: { class: "test-123", inner }});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, it's because this is like:

<Row class="test-123" inner />

but it should be:

<Row class="test-123" bind:inner />

It doesn't seem to be possible to achieve this with @testing-library/svelte (v3.0.3 as used here, and the latest available at time of writing) - though possibly it should be if it updated its version of Svelte's component API - it's not clear to me what context is, it sounds like maybe { props: {...}, context: {"bind:inner": inner } should work, but it claims that:

Valid Svelte options are [anchor,props,hydrate,intro]

which is incomplete, per the link above.

expect(inner.classList).toContain("test-123")
});
});