Skip to content

fix #1218 where carousel is not calculating children correctly #1219

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 2 commits into from
Mar 22, 2021

Conversation

scripter-co
Copy link
Contributor

Description

A fix for #1218

Changelog

Replaced children.length with Reacts children count helper.

@@ -1,50 +1,53 @@
import React from 'react';
import * as uut from '../CarouselPresenter';

describe('Carousel presenter', () => {
it('should getChildrenLength', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

you could argue this test is pointless now and can be deleted. It's just testing that React.Children.count works - which doesn't need to be tested.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Why are you changing the tests from objects to tags?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

because {} is not a valid component in react. If you try and call React.children.count() with {} you'll get Objects are not valid as a React child (found: object with keys {}). If you meant to render a collection of children, use an array instead.

@ethanshar ethanshar self-requested a review March 13, 2021 08:20
@ethanshar ethanshar self-assigned this Mar 13, 2021
@ethanshar ethanshar requested review from Inbal-Tish and removed request for ethanshar March 14, 2021 07:46
@ethanshar ethanshar assigned Inbal-Tish and unassigned ethanshar Mar 14, 2021
export function getChildrenLength(props: CarouselProps): number {
const length = _.get(props, 'children.length') || 0;
return length;
type PropsWithChildren = CarouselProps & { children?: ReactNode }
Copy link
Collaborator

Choose a reason for hiding this comment

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

'children' are not already part of CarouselProps?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No - It is fine in the component because the class uses a generic which looks like readonly props: Readonly<P> & Readonly<{ children?: ReactNode }>;

@Inbal-Tish Inbal-Tish merged commit f3bdb18 into wix:master Mar 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants