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

[tds-ui] onChange 함수가 중복 실행되지 않도록 수정합니다. #3532

Merged
merged 2 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions packages/tds-ui/src/components/tabs/tab-base.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,10 @@ function TabBaseComponent<Value extends number | string | symbol>(

const handleClick: MouseEventHandler = () => {
onClick()
tabs.onChange?.(value)
}

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
Loading