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

Input 의 useId 를 react 제공 함수로 변경했다 #36

Merged
merged 3 commits into from
Oct 12, 2023
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
7 changes: 3 additions & 4 deletions packages/co-design-core/src/components/Input/Input.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import React, { forwardRef } from 'react';
import React, { forwardRef, useId } from 'react';
import { useCoTheme, CoComponentProps, CoSize, PolymorphicComponentProps, PolymorphicRef, CoRadius, ClassNames } from '@co-design/styles';
import { View } from '../View';
import useStyles from './Input.style';
import { Text, TextProps } from '../Text';
import { useId } from '@co-design/hooks';

export type InputStylesNames = ClassNames<typeof useStyles>;

Expand Down Expand Up @@ -111,7 +110,7 @@ export const Input: InputComponent & { displayName?: string } = forwardRef(
return (
<Wrapper>
{label && (
<label htmlFor={inputId} className={classes.label}>
<label htmlFor={inputId + name} className={classes.label}>
<Text className={classes.labelText} {...labelTextProps}>
{label}
</Text>
Expand Down Expand Up @@ -139,7 +138,7 @@ export const Input: InputComponent & { displayName?: string } = forwardRef(
required={required}
disabled={disabled}
style={{ paddingRight: rightSection ? rightSectionWidth : theme.spacing.small }}
id={inputId}
id={inputId + name}
/>
{rightSection && (
<div
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import React, { useState } from 'react';
import { Tooltip } from '../../Tooltip';
import { Input } from '../Input';
import { Modal } from '../../Modal';

export default {
title: '@co-design/core/Input',
Expand Down Expand Up @@ -115,3 +116,26 @@ export const WithLabel = {
);
},
};

// Storybook Context 변경으로 인한 리렌더링으로 focus 풀림
export const AutoFocus = {
render: (props) => {
const [opened, setOpened] = useState(false);
return (
<>
<div style={{ width: 400, padding: 24 }}>
<button
onClick={() => {
setOpened(true);
}}
>
open modal
</button>
</div>
<Modal opened={opened} onClose={() => setOpened(false)}>
<Input autoFocus {...props} />
</Modal>
</>
);
},
};