Skip to content

Commit

Permalink
Tabs 컴포넌트에서 onChange 로직을 처리하도록 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
guswl98 committed Jan 6, 2025
1 parent 017a295 commit 13d9a24
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/tds-ui/src/components/tabs/tab-base.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function TabBaseComponent<Value extends number | string | symbol>(
}

const handleFocus: FocusEventHandler = () => {
tabs.onChange?.(value)
tabs.handleFocusChanged?.(value)
}

const handleKeyDown: KeyboardEventHandler = (event) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/tds-ui/src/components/tabs/tabs-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export interface TabsContextValue<Value extends number | string | symbol> {
value: Value
variant: TabVariant
scroll: boolean
onChange?: (value: Value) => void
handleFocusChanged: (value: Value) => void
}

export const TabsContext = createContext<TabsContextValue<string> | undefined>(
Expand Down
10 changes: 9 additions & 1 deletion packages/tds-ui/src/components/tabs/tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,16 @@ export const Tabs = <Value extends number | string | symbol>({
TabsContextValue<Value> | undefined
>

function handleFocusChanged(newValue: Value) {
if (value !== newValue) {
onChange?.(newValue)
}
}

return (
<TabsContextProvider value={{ id, value, variant, scroll, onChange }}>
<TabsContextProvider
value={{ id, value, variant, scroll, handleFocusChanged }}
>
{children}
</TabsContextProvider>
)
Expand Down

0 comments on commit 13d9a24

Please sign in to comment.