본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

입력창

원문 보기 위키 갱신

입력창 (Sender)

채팅 시나리오에서 사용하는 입력창 컴포넌트예요.

출처: 문서

본문

언제 사용하나요?

  • 채팅 시나리오에서 입력창을 만들어야 할 때

코드 예제

API

공통 props 참고: 공통 props

SenderProps

Property 설명 타입 기본값 버전
allowSpeech 음성 입력을 허용할지 여부 boolean | SpeechConfig false -
classNames 스타일 클래스명 아래 참고 - -
components 커스텀 컴포넌트 Record<'input', ComponentType> - -
defaultValue 입력창 기본값 string - -
disabled 비활성화 여부 boolean false -
loading 로딩 상태 여부 boolean false -
suffix 뒤쪽 콘텐츠예요. 기본 액션 버튼이 표시돼요. 기본 액션 버튼이 필요 없으면 suffix={false}로 설정할 수 있어요 React.ReactNode | false | (oriNode: React.ReactNode, info: { components: ActionsComponents; }) => React.ReactNode | false oriNode 2.0.0
header 헤더 패널 React.ReactNode | false | (oriNode: React.ReactNode, info: { components: ActionsComponents; }) => React.ReactNode | false false -
prefix 앞쪽 콘텐츠 React.ReactNode | false | (oriNode: React.ReactNode, info: { components: ActionsComponents; }) => React.ReactNode | false false -
footer 푸터 콘텐츠 React.ReactNode | false | (oriNode: React.ReactNode, info: { components: ActionsComponents; }) => React.ReactNode | false false -
readOnly 입력창을 읽기 전용으로 만들지 여부 boolean false -
rootClassName 루트 요소 스타일 클래스 string - -
styles 시맨틱 스타일 정의 아래 참고 - -
submitType 제출 방식 SubmitType enter | shiftEnter -
value 입력창 값 string - -
onSubmit 전송 버튼을 클릭했을 때 호출되는 콜백 (message: string, slotConfig: SlotConfigType[], skill: SkillType) => void - -
onChange 입력창 값이 바뀔 때 호출되는 콜백 (value: string, event?: React.FormEvent<HTMLTextAreaElement> | React.ChangeEvent<HTMLTextAreaElement>, slotConfig: SlotConfigType[], skill: SkillType) => void - -
onCancel 취소 버튼을 클릭했을 때 호출되는 콜백 () => void - -
onPaste 붙여넣기 콜백 React.ClipboardEventHandler<HTMLElement> - -
onPasteFile 파일 붙여넣기 콜백 (files: FileList) => void - -
onKeyDown 키보드 입력 콜백 (event: React.KeyboardEvent) => void | false - -
onFocus 포커스를 얻을 때 콜백 React.FocusEventHandler<HTMLTextAreaElement> - -
onBlur 포커스를 잃을 때 콜백 React.FocusEventHandler<HTMLTextAreaElement> - -
placeholder 입력창 플레이스홀더 string - -
autoSize 내용에 맞춰 높이를 자동 조정해요. true | false 또는 객체: { minRows: 2, maxRows: 6 }로 설정할 수 있어요 boolean | { minRows?: number; maxRows?: number } { maxRows: 8 } -
slotConfig 슬롯 구성이에요. 설정하면 입력창이 슬롯 모드로 전환되어 구조화된 입력을 지원해요. 이 모드에서는 value와 defaultValue 설정이 무효화돼요. SlotConfigType[] - 2.0.0
skill 스킬 구성이에요. 입력창이 슬롯 모드로 전환되어 구조화된 입력을 지원해요. 이 모드에서는 value와 defaultValue 설정이 무효화돼요. SkillType - 2.0.0
interface SkillType {
  title?: React.ReactNode;
  value: string;
  toolTip?: TooltipProps;
  closable?:
    | boolean
    | {
        closeIcon?: React.ReactNode;
        onClose?: React.MouseEventHandler<HTMLDivElement>;
        disabled?: boolean;
      };
}
type SpeechConfig = {
  // When `recording` is set, the built-in voice input feature will be disabled.
  // Developers need to implement third-party voice input functionality.
  recording?: boolean;
  onRecordingChange?: (recording: boolean) => void;
};
type ActionsComponents = {
  SendButton: React.ComponentType<ButtonProps>;
  ClearButton: React.ComponentType<ButtonProps>;
  LoadingButton: React.ComponentType<ButtonProps>;
  SpeechButton: React.ComponentType<ButtonProps>;
};

Sender Ref

Property 설명 타입 기본값 버전
inputElement 입력 요소 HTMLTextAreaElement - -
nativeElement 바깥 컨테이너 HTMLDivElement - -
focus 포커스를 얻어요. cursor = 'slot'이면 타입이 input인 첫 슬롯에 포커스가 가고, 해당하는 input이 없으면 end와 동일하게 동작해요 (option?: { preventScroll?: boolean, cursor?: 'start' | 'end' | 'all' | 'slot' }) - -
blur 포커스를 제거해요 () => void - -
insert 텍스트나 슬롯을 삽입해요. 슬롯을 사용하려면 slotConfig가 설정되어 있어야 해요 (value: string) => void | (slotConfig: SlotConfigType[], position: insertPosition, replaceCharacters: string, preventScroll: boolean) => void; - -
clear 내용을 지워요 () => void - -
getValue 현재 내용과 구조화된 구성을 가져와요 () => { value: string; slotConfig: SlotConfigType[], skill: SkillType } - -

SlotConfigType

Property 설명 타입 기본값 버전
type 노드 타입이에요. 렌더링할 컴포넌트 타입을 결정하며 필수예요 'text' | 'input' | 'select' | 'tag' | 'content' | 'custom' - 2.0.0
key 고유 식별자예요. type이 text일 때는 생략할 수 있어요 string - -
formatResult 최종 결과를 포맷해요. 모든 슬롯 타입(content 포함)에 적용돼요 (value: any) => string - 2.0.0
text 노드 속성
Property 설명 타입 기본값 버전
value 텍스트 내용 string - 2.0.0
input 노드 속성
Property 설명 타입 기본값 버전
props.placeholder 플레이스홀더 string - 2.0.0
props.defaultValue 기본값 string | number | readonly string[] - 2.0.0
select 노드 속성
Property 설명 타입 기본값 버전
props.options 옵션 배열, 필수 string[] - 2.0.0
props.placeholder 플레이스홀더 string - 2.0.0
props.defaultValue 기본값 string - 2.0.0
tag 노드 속성
Property 설명 타입 기본값 버전
props.label 태그 내용, 필수 ReactNode - 2.0.0
props.value 태그 값 string - 2.0.0
content 노드 속성
Property 설명 타입 기본값 버전
props.defaultValue 기본값 any - 2.1.0
props.placeholder 플레이스홀더 string - 2.1.0
custom 노드 속성
Property 설명 타입 기본값 버전
props.defaultValue 기본값 any - 2.0.0
customRender 커스텀 렌더링 함수 (value: any, onChange: (value: any) => void, props: { disabled?: boolean, readOnly?: boolean }, item: SlotConfigType) => React.ReactNode - 2.0.0

Sender.Header

Property 설명 타입 기본값 버전
children 패널 내용 ReactNode - -
classNames 스타일 클래스명 아래 참고 - -
closable 닫을 수 있는지 여부 boolean true -
forceRender 강제 렌더링이에요. 초기화 시점에 내부 요소를 참조해야 할 때 사용해요 boolean false -
open 펼침 여부 boolean - -
styles 시맨틱 스타일 정의 아래 참고 - -
title 제목 ReactNode - -
onOpenChange 펼침 상태가 바뀔 때 호출되는 콜백 (open: boolean) => void - -

Sender.Switch

Property 설명 타입 기본값 버전
children 일반 콘텐츠 ReactNode - 2.0.0
checkedChildren 체크됐을 때 콘텐츠 ReactNode - 2.0.0
unCheckedChildren 체크 해제됐을 때 콘텐츠 ReactNode - 2.0.0
icon 아이콘 컴포넌트 설정 ReactNode - 2.0.0
disabled 비활성화 여부 boolean false 2.0.0
loading 로딩 스위치 boolean - 2.0.0
defaultValue 기본 체크 상태 boolean - 2.0.0
value 스위치 값 boolean false 2.0.0
onChange 바뀔 때 호출되는 콜백 function(checked: boolean) - 2.0.0
rootClassName 루트 요소 스타일 클래스 string - 2.0.0

⚠️ 슬롯 모드 주의사항

  • 슬롯 모드에서는 value와 defaultValue 속성이 무효예요. ref와 콜백 이벤트로 입력창 값과 슬롯 구성을 얻으세요.
  • **슬롯 모드에서 onChange/onSubmit 콜백의 세 번째 인자 config**는 현재 구조화된 내용을 가져오는 용도로만 쓰여요.

예제:

// ❌ Incorrect usage, slotConfig and skill are for uncontrolled usage
const [config, setConfig] = useState([]);
const [skill, setSkill] = useState([]);
<Sender
  slotConfig={config}
  skill={skill}
  onChange={(value, e, config, skill) => {
    setConfig(config);
    setSkill(skill)
  }}
/>

// ✅ Correct usage
<Sender
  key={key}
  slotConfig={config}
  skill={skill}
  onChange={(value, _e, config, skill) => {
    // Only used to get structured content
    setKey('new_key')
  }}
/>

Semantic DOM

테마 변수 (Design Token)

더 알아보기

채팅 화면의 출력 쪽이 궁금하면 말풍선(Bubble) 문서를 함께 보면 좋아요. useXChat과 연동하는 방법은 X SDK 문서에서 확인할 수 있어요.