Skip to content

Commit

Permalink
fix: tabs trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
lovrozagar committed Jul 12, 2024
1 parent 176fe47 commit 40c3a4a
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 18 deletions.
16 changes: 14 additions & 2 deletions app.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
import { Tabs, TabsTrigger, TabsTriggerList } from '@/components'
import React, { useState } from 'react'

const App = () => {
const [state, setValue] = useState(false)
const [state, setValue] = useState('')

return <div className='h-screen w-full flex flex-col justify-center items-center gap-8'> </div>
return (
<div className='h-screen w-full flex flex-col justify-center items-center gap-8'>
<Tabs value={state} onValueChange={setValue}>
<TabsTriggerList>
<TabsTrigger asChild value={1}>
<a>Trigger 1</a>
</TabsTrigger>
<TabsTrigger value={2}>Trigger 2</TabsTrigger>
</TabsTriggerList>
</Tabs>
</div>
)
}

export { App }
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@renderui/core",
"version": "1.4.5",
"version": "1.4.6",
"private": false,
"description": "React UI library with highly modular and ready-out-of-the-box components",
"license": "MIT",
Expand Down
51 changes: 37 additions & 14 deletions src/components/tabs/components/tabs-trigger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { getHandleTriggerPress } from '@/components/tabs/utils/get-handdle-trigg

const TabsTrigger = React.forwardRef<TabsTriggerRef, TabsTriggerProps>((props, ref) => {
const {
asChild,
value,
className,
children,
Expand All @@ -44,6 +45,7 @@ const TabsTrigger = React.forwardRef<TabsTriggerRef, TabsTriggerProps>((props, r
return (
<TabsTriggerPrimitive asChild disabled={isDisabled} value={value as string}>
<Button
asChild={asChild}
ref={ref}
data-slot='trigger'
color={color ?? rootColor}
Expand All @@ -65,20 +67,41 @@ const TabsTrigger = React.forwardRef<TabsTriggerRef, TabsTriggerProps>((props, r
)}
{...restProps}
>
<span
data-slot='trigger-children-container'
className={cn(
DEFAULT_TABS_TRIGGER_CHILDREN_CONTAINER_CLASSNAME,
childrenContainerClassName,
)}
{...restChildrenContainerProps}
>
{children}
</span>
<span aria-hidden className='invisible'>
{children}
</span>
{isActive ? <TabsCursor /> : null}
{asChild ? (
<span className='w-full h-full rounded-[inherit] text-[inherit]'>
<span
data-slot='trigger-children-container'
className={cn(
DEFAULT_TABS_TRIGGER_CHILDREN_CONTAINER_CLASSNAME,
childrenContainerClassName,
)}
{...restChildrenContainerProps}
>
{children}
</span>
<span aria-hidden className='invisible'>
{children}
</span>
{isActive ? <TabsCursor /> : null}
</span>
) : (
<>
<span
data-slot='trigger-children-container'
className={cn(
DEFAULT_TABS_TRIGGER_CHILDREN_CONTAINER_CLASSNAME,
childrenContainerClassName,
)}
{...restChildrenContainerProps}
>
{children}
</span>
<span aria-hidden className='invisible'>
{children}
</span>
{isActive ? <TabsCursor /> : null}
</>
)}
</Button>
</TabsTriggerPrimitive>
)
Expand Down
2 changes: 1 addition & 1 deletion src/components/tabs/constants/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const INACTIVE_TABS_TRIGGER_CLASSNAME =
'text-mode-contrast transition-[color] duration-fast data-[hover="true"]:data-[state="inactive"]:text-primary'

const DEFAULT_TABS_TRIGGER_CHILDREN_CONTAINER_CLASSNAME =
'absolute inset-0 z-[20] flex size-full items-center justify-center gap-3 text-[inherit]'
'absolute inset-0 z-[2] flex size-full items-center justify-center gap-3 text-[inherit]'

export {
DEFAULT_TABS_CLASSNAME,
Expand Down

0 comments on commit 40c3a4a

Please sign in to comment.