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

Fix children mapping keys in Carousel, CodeMockup, and Range #231

Merged
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/Carousel/Carousel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ const Carousel = forwardRef<HTMLDivElement, CarouselProps>(
>
{children.map((child, i) => {
return cloneElement(child, {
key: i,
innerRef: itemRefs[i],
index: i + 1,
children: child.props.children,
Expand Down
9 changes: 7 additions & 2 deletions src/CodeMockup/CodeMockup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { forwardRef } from 'react'
import { twMerge } from 'tailwind-merge'

import { IComponentBaseProps } from '../types'
import { CodeMockupLine } from './CodeMockupLine'
import { CodeMockupLine, CodeMockupLineProps } from './CodeMockupLine'

export type CodeMockupProps = React.HTMLAttributes<HTMLDivElement> &
IComponentBaseProps
Expand All @@ -19,7 +19,12 @@ const CodeMockup = forwardRef<HTMLDivElement, CodeMockupProps>(
className={classes}
ref={ref}
>
{children}
{React.Children.map(children, (child, index) => {
const childComponent = child as React.ReactElement<CodeMockupLineProps>
return React.cloneElement(childComponent, {
key: index,
})
})}
</div>
)
}
Expand Down
4 changes: 2 additions & 2 deletions src/Range/Range.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ const Range = forwardRef<HTMLInputElement, RangeProps>(
/>
{isNumeric(step) && (
<div className="w-full flex justify-between text-xs px-2">
{[...Array(numSteps + 1)].map(() => {
return <span>|</span>
{[...Array(numSteps + 1)].map((_, i) => {
return <span key={i}>|</span>
})}
</div>
)}
Expand Down