react-carousel icon indicating copy to clipboard operation
react-carousel copied to clipboard

The width of the slide in accordance with the width of the content.

Open Dima-Dim opened this issue 5 years ago • 4 comments

If you use a carousel for texts, then the same width for the slides may not be optimal and it may be convenient to be able to set the max-width of the slide, but the widths themselves should be adjusted to the width of the content.

Dima-Dim avatar Jul 02 '20 12:07 Dima-Dim

@Dima-Dim

Thanks for this suggestion but could you also provide the following?

  • example code using react-carousel
  • a screenshot of the current behavior
  • an image showing the expected behavior

piotr-s-brainhub avatar Jul 02 '20 14:07 piotr-s-brainhub

Suppose we have the following initial data:

const data = [
  {
    id: 0,
    name: "Simple Long Text",
  },
  {
    id: 1,
    name: "Text",
  },
];

получаем вот такой вариант: 2020-07-03 react-carousel_1 these are two slides 172px wide. Yes, some stylization has been applied here, but it does not affect the mechanism for forming the width of the carousel elements.

I would like to be able to get something like this: 2020-07-03 react-carousel_2 In this case, these are 124px and 38px slides.

Now we achieve this with:

const resetStaticWidthForItems = (node: HTMLUListElement) => {
  const items = node.querySelectorAll("li");
  items.forEach((item) => {
    item.setAttribute("style", "width: auto;");
  })
};

Dima-Dim avatar Jul 03 '20 11:07 Dima-Dim

Thanks @Dima-Dim

Are you able to provide code applicable in the clickable docs?

piotr-s-brainhub avatar Jul 06 '20 12:07 piotr-s-brainhub

This fix does not work! When the carousel is set to infinite and you change the width of the carousel items the logic that moves the carousel fails. For me it continues to jump back to the end of the carousel when it is about to complete a full iteration.

samcohen9617 avatar Jan 14 '21 22:01 samcohen9617