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

Tabview: Tabs are not styled when use PrimeReact & Tailwind default style #6868

Closed
LB-sx opened this issue Jul 11, 2024 · 12 comments · Fixed by #7057
Closed

Tabview: Tabs are not styled when use PrimeReact & Tailwind default style #6868

LB-sx opened this issue Jul 11, 2024 · 12 comments · Fixed by #7057
Assignees
Labels
Component: Tailwind Tailwind specific issue Component: Unstyled Issue related to unstyled/passthrough attributes
Milestone

Comments

@LB-sx
Copy link

LB-sx commented Jul 11, 2024

Describe the bug

When I'm using PrimeReact in unstyled mode with tailwind the tabview is not styled with the default pt tailwind style while it is working for the other components.

image

Reproducer

https://stackblitz.com/edit/q1g8yj

PrimeReact version

10.7.0

React version

18.x

Language

TypeScript

Build / Runtime

Vite

Browser(s)

Edge & Chrome 126

Steps to reproduce the behavior

Execute the Stackblitz, as an output the tabView tabs are shown unstyled.

Expected behavior

Default Tailwind style to be applied.

@LB-sx LB-sx added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Jul 11, 2024
@melloware melloware added Component: Unstyled Issue related to unstyled/passthrough attributes and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels Jul 11, 2024
@eklee
Copy link

eklee commented Aug 13, 2024

Still happening on the latest 10.8.2 build. I tried passing in the default tabview styling (here:

) manually and it also doesn't work. Any ideas on how to workaround this?

@melloware
Copy link
Member

@gcko @ivanpajon need some more Tailwind expertise here.

@ivanpajon
Copy link
Contributor

ivanpajon commented Aug 13, 2024

I downloaded to local the reproducer and without any change it works fine for me.

image

But the fact that in the reproducer looks bad is weird... As a workaround maybe you @LB-sx @eklee can try this:

image

@melloware
Copy link
Member

@LB-sx could it just be a StackBlitz thing with Tailwind?

@eklee
Copy link

eklee commented Aug 13, 2024

Interestingly, adding 'unstyled' and the pt properties seem to work. But visually there seems to be issue when a tab is clicked: a highlighted border is drawn around the tab name (this doesn't happen on the styled theme version):

image

@LB-sx
Copy link
Author

LB-sx commented Aug 14, 2024

@eklee it is exactly the workaround I am using at the moment.

Interestingly, adding 'unstyled' and the pt properties seem to work. But visually there seems to be issue when a tab is clicked: a highlighted border is drawn around the tab name (this doesn't happen on the styled theme version):

image

@LB-sx
Copy link
Author

LB-sx commented Aug 14, 2024

@LB-sx could it just be a StackBlitz thing with Tailwind?

No I am currently prototyping a framework including PrimeReact in a R&D project, and I'm facing this issue in this project

@melloware
Copy link
Member

Its weird you shouldn't have to add unstyled if you are in unstyled mode. Something has to be wrong with TabView.

@melloware melloware added the Component: Tailwind Tailwind specific issue label Aug 14, 2024
@melloware
Copy link
Member

@gcko any chance you can look at this one too. This is very strange.

@gcko
Copy link
Contributor

gcko commented Aug 14, 2024

@gcko any chance you can look at this one too. This is very strange.

Sure I'll check it out in a bit

@gcko
Copy link
Contributor

gcko commented Aug 14, 2024

Ahh, so this is related to TabView and TabPanel @melloware @eklee @LB-sx

Yea I ran into this issue back when it was first released in November, and I handled it locally. I guess I should look at addressing it directly in the PrimeReact codebase 🤔

While I am working on that, here is my current solution (in Typescript)

export const tabPanelPassThrough = (contentClassNames = '') => {
  const headerActionClassnames = (
    parent: TabViewPassThroughMethodOptions,
    context: TabViewContext,
  ) => {
    return classNames(
      'items-center cursor-pointer flex overflow-hidden relative select-none text-decoration-none user-select-none', // Flex and overflow styles.
      'border-b-2 p-2 font-medium rounded-t-lg transition-shadow duration-200 m-0', // Border, padding, font, and transition styles.
      'transition-colors duration-200', // Transition duration style.
      'focus:outline-none focus:outline-offset-0 focus:shadow-[inset_0_0_0_0.2rem_rgba(147,197,253,0.5)]', // Focus styles.
      {
        // Below are for the INACTIVE tab
        'border-slate-700 bg-blue-900 text-white/60 hover:bg-blue-900 hover:text-white/80':
          parent.state.activeIndex !== context.index, // Condition-based hover styles.
        // Below are for the ACTIVE Tab
        'bg-blue-900 border-blue-900 text-white': parent.state.activeIndex === context.index, // Condition-based active styles.
      },
    );
  };
  return {
    header: ({ props }: { props: TabPanelProps }) => ({
      className: classNames('mr-0', {
        'cursor-default pointer-events-none select-none user-select-none opacity-60':
          props.disabled,
      }), // Margin and condition-based styles.
    }),
    headerAction: ({
      parent,
      context,
    }: {
      parent: TabViewPassThroughMethodOptions;
      context: TabViewContext;
    }) => ({
      className: headerActionClassnames(parent, context),
      style: { marginBottom: '-.5rem' }, // Negative margin style.
    }),
    headerTitle: {
      className: classNames('leading-none whitespace-nowrap'), // Leading and whitespace styles.
    },
    content: {
      className: classNames(
        'bg-gray-900 p-2 border-slate-700 text-white/80 rounded-bl-2xl rounded-br-2xl',
        'overflow-y-auto scrollbar-styled',
        contentClassNames,
      ), // Background, padding, border, and text styles.
    },
  };
};

Below is a basic example of of this in use:

import { ReactNode, useMemo } from 'react';
import { TabPanel, TabView } from 'primereact/tabview';
import { tabPanelPassThrough } from 'path/to/tabPanelPassThrough';

interface TabItem {
  header: string;
  node: ReactNode;
}

export default function TDPanel(): ReactNode {
  const tabs: TabItem[] = useMemo(
    () => [
      { header: 'Risk', node: <div className="min-h-72">Risk</div> },
      { header: 'Spot', node: <div className="min-h-72">Spot</div> },
      { header: 'Loan', node: <div className="min-h-72">Loan</div> },
    ],
    [],
  );
  return (
    <div>
      <TabView>
        {tabs.map((t) => (
          <TabPanel header={t.header} key={t.header} pt={tabPanelPassThrough()}>
            {t.node}
          </TabPanel>
        ))}
      </TabView>
    </div>
  );
}

@melloware
Copy link
Member

@gcko thank you a PR would be welcome!

gcko added a commit to gcko/primereact that referenced this issue Aug 16, 2024
@melloware melloware added this to the 10.8.3 milestone Aug 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Tailwind Tailwind specific issue Component: Unstyled Issue related to unstyled/passthrough attributes
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants