Set the ref on the actual carousel div
This commit is contained in:
parent
ea5fb4ec5a
commit
c30e8f1fd9
2 changed files with 8 additions and 4 deletions
|
@ -1,5 +1,5 @@
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import React from 'react';
|
import React, { forwardRef } from 'react';
|
||||||
|
|
||||||
const justifyContentOptions = {
|
const justifyContentOptions = {
|
||||||
between: 'justify-between',
|
between: 'justify-between',
|
||||||
|
@ -32,6 +32,8 @@ interface IHStack {
|
||||||
alignItems?: 'top' | 'bottom' | 'center' | 'start',
|
alignItems?: 'top' | 'bottom' | 'center' | 'start',
|
||||||
/** Extra class names on the <div> element. */
|
/** Extra class names on the <div> element. */
|
||||||
className?: string,
|
className?: string,
|
||||||
|
/** Children */
|
||||||
|
children?: React.ReactNode,
|
||||||
/** Horizontal alignment of children. */
|
/** Horizontal alignment of children. */
|
||||||
justifyContent?: 'between' | 'center' | 'start' | 'end' | 'around',
|
justifyContent?: 'between' | 'center' | 'start' | 'end' | 'around',
|
||||||
/** Size of the gap between elements. */
|
/** Size of the gap between elements. */
|
||||||
|
@ -43,12 +45,13 @@ interface IHStack {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Horizontal row of child elements. */
|
/** Horizontal row of child elements. */
|
||||||
const HStack: React.FC<IHStack> = (props) => {
|
const HStack = forwardRef<HTMLDivElement, IHStack>((props, ref) => {
|
||||||
const { space, alignItems, grow, justifyContent, className, ...filteredProps } = props;
|
const { space, alignItems, grow, justifyContent, className, ...filteredProps } = props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
{...filteredProps}
|
{...filteredProps}
|
||||||
|
ref={ref}
|
||||||
className={classNames('flex', {
|
className={classNames('flex', {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
[alignItemsOptions[alignItems]]: typeof alignItems !== 'undefined',
|
[alignItemsOptions[alignItems]]: typeof alignItems !== 'undefined',
|
||||||
|
@ -60,6 +63,6 @@ const HStack: React.FC<IHStack> = (props) => {
|
||||||
}, className)}
|
}, className)}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
});
|
||||||
|
|
||||||
export default HStack;
|
export default HStack;
|
||||||
|
|
|
@ -110,7 +110,7 @@ const FeedCarousel = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card variant='rounded' size='lg' ref={setCardRef} className='relative' data-testid='feed-carousel'>
|
<Card variant='rounded' size='lg' className='relative' data-testid='feed-carousel'>
|
||||||
<div>
|
<div>
|
||||||
{hasPrevPage && (
|
{hasPrevPage && (
|
||||||
<div>
|
<div>
|
||||||
|
@ -131,6 +131,7 @@ const FeedCarousel = () => {
|
||||||
space={8}
|
space={8}
|
||||||
className='z-0 flex transition-all duration-200 ease-linear scroll'
|
className='z-0 flex transition-all duration-200 ease-linear scroll'
|
||||||
style={{ transform: `translateX(-${(currentPage - 1) * 100}%)` }}
|
style={{ transform: `translateX(-${(currentPage - 1) * 100}%)` }}
|
||||||
|
ref={setCardRef}
|
||||||
>
|
>
|
||||||
{isLoading ? (
|
{isLoading ? (
|
||||||
new Array(pageSize).fill(0).map((_, idx) => (
|
new Array(pageSize).fill(0).map((_, idx) => (
|
||||||
|
|
Loading…
Reference in a new issue