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

Truncate don't work in Command/Scroll area #1421

Closed
Natchii59 opened this issue Sep 1, 2023 · 2 comments
Closed

Truncate don't work in Command/Scroll area #1421

Natchii59 opened this issue Sep 1, 2023 · 2 comments

Comments

@Natchii59
Copy link

Hello, I would like to have a combobox component, with a scrollable area. I set a fixed width to 200px. The problem is when the number of characters exceeds the width, my truncate attribute (from tailwindcss) doesn't work because of the ScrollArea. I tried without it and it works. Do you have a solution for using truncate with ScrollArea?

My code:

<CommandGroup heading={'Wallets'}>
  <ScrollArea className='h-[96px]'>
    {wallets.map(wallet => (
      <CommandItem
        key={wallet.id}
        onSelect={() => {
          setWallet(wallet)
          setPopoverOpen(false)
        }}
        className='text-sm'
      >
        <Avatar className='mr-2 h-5 w-5'>
          <AvatarImage
            src={`https://avatar.vercel.sh/${wallet.id}.png`}
            alt={wallet.name}
          />
          <AvatarFallback />
        </Avatar>

        <span className='flex-auto truncate'>{wallet.name}</span>  <----- HERE

        {selectWallet?.id === wallet.id && (
          <Icons.check className='h-4 w-4' />
        )}
      </CommandItem>
    ))}
  </ScrollArea>
</CommandGroup>

Screenshot:
image

@WangLarry
Copy link

@Natchii59 radix-ui/primitives#926 (comment)

@holdenmatt
Copy link

holdenmatt commented Sep 8, 2023

I was running into a similar issue (child elements of a ScrollArea not respecting w-full).

After finding this issue, here's a simple workaround for shadcn adapted from the radix-ui issue thread:

<ScrollArea className="[&>div>div]:!block">{children}</ScrollArea>

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

No branches or pull requests

3 participants