Skip to content

Commit

Permalink
Merge pull request #36 from cobaltinc/park/input-useId
Browse files Browse the repository at this point in the history
Input 의 useId 를 react 제공 함수로 변경했다
  • Loading branch information
healtheloper authored Oct 12, 2023
2 parents 52e2f31 + 2f2a906 commit 87d857f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
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>
</>
);
},
};

0 comments on commit 87d857f

Please sign in to comment.