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

옵션 (Option)

원문 보기 위키 갱신

select 같은 다양한 폼 컨트롤 안에서 선택 가능한 항목을 정의하는 컴포넌트예요. 드롭다운 목록의 각 항목을 나타낼 때 쓰여요. _ | SlOption, Shoelace 2.0부터 제공되고 있으며 stable 상태예요.

출처: 문서

본문

| SlOption — Since 2.0, stable

옵션(Option)은 select 같은 다양한 폼 컨트롤 안에서 선택 가능한 항목을 정의해요.

<sl-select label="Select one">
  <sl-option value="option-1">Option 1</sl-option>
  <sl-option value="option-2">Option 2</sl-option>
  <sl-option value="option-3">Option 3</sl-option>
</sl-select>
import SlOption from '@shoelace-style/shoelace/dist/react/option';
import SlSelect from '@shoelace-style/shoelace/dist/react/select';
const App = () => (
  <SlSelect>
    <SlOption value="option-1">Option 1</SlOption>
    <SlOption value="option-2">Option 2</SlOption>
    <SlOption value="option-3">Option 3</SlOption>
  </SlSelect>
);

Examples

Disabled

disabled 속성을 쓰면 옵션을 비활성화해서 선택할 수 없게 할 수 있어요.

<sl-select label="Select one">
  <sl-option value="option-1">Option 1</sl-option>
  <sl-option value="option-2" disabled>Option 2</sl-option>
  <sl-option value="option-3">Option 3</sl-option>
</sl-select>
import SlOption from '@shoelace-style/shoelace/dist/react/option';
import SlSelect from '@shoelace-style/shoelace/dist/react/select';
const App = () => (
  <SlSelect>
    <SlOption value="option-1">Option 1</SlOption>
    <SlOption value="option-2" disabled>
      Option 2
    </SlOption>
    <SlOption value="option-3">Option 3</SlOption>
  </SlSelect>
);

Prefix & Suffix

prefix와 suffix 슬롯을 써서 메뉴 항목의 시작과 끝에 아이콘을 추가할 수 있어요.

<sl-select label="Select one">
  <sl-option value="option-1">
    <sl-icon slot="prefix" name="envelope"></sl-icon>
    Email
    <sl-icon slot="suffix" name="patch-check"></sl-icon>
  </sl-option>
  <sl-option value="option-2">
    <sl-icon slot="prefix" name="telephone"></sl-icon>
    Phone
    <sl-icon slot="suffix" name="patch-check"></sl-icon>
  </sl-option>
  <sl-option value="option-3">
    <sl-icon slot="prefix" name="chat-dots"></sl-icon>
    Chat
    <sl-icon slot="suffix" name="patch-check"></sl-icon>
  </sl-option>
</sl-select>

Importing

autoloader나 전통적인 loader를 사용하고 있다면 이 부분은 건너뛰어도 돼요. 그 외에는 아래 스니펫 중 원하는 걸 골라 이 컴포넌트만 골라 가져올 수 있어요.

Script / Import / Bundler / React 방식이 준비되어 있어요.

CDN에서 <script> 태그로 이 컴포넌트를 가져오려면:

<script type="module" src="https://cdn.jsdelivr.net/npm/@shoelace-style/shoelace@2.20.1/cdn/components/option/option.js"></script>

CDN에서 JavaScript import로 가져오려면:

import 'https://cdn.jsdelivr.net/npm/@shoelace-style/shoelace@2.20.1/cdn/components/option/option.js';

Bundler를 사용해 가져오려면:

import '@shoelace-style/shoelace/dist/components/option/option.js';

React 컴포넌트로 가져오려면:

import SlOption from '@shoelace-style/shoelace/dist/react/option';

Slots

Name Description
(default) The option’s label.
prefix Used to prepend an icon or similar element to the menu item.
suffix Used to append an icon or similar element to the menu item.

슬롯 사용법에 대해 더 알아보세요.

Properties

Name Description Reflects Type Default
value The option’s value. When selected, the containing form control will receive this value. The value
                must be unique from other options in the same group. Values may not contain spaces, as spaces are
                used as delimiters when listing multiple values. |  | `string` | `''` |

| disabled | Draws the option in a disabled state, preventing selection. | | boolean | false | | updateComplete | A read-only promise that resolves when the component has finished updating. | | | |

속성과 프로퍼티에 대해 더 알아보세요.

Methods

Name Description Arguments
getTextLabel() Returns a plain text label based on the option’s content. -

메서드에 대해 더 알아보세요.

Parts

Name Description
checked-icon The checked icon, an `` element.
base The component’s base wrapper.
label The option’s label.
prefix The container that wraps the prefix.
suffix The container that wraps the suffix.

CSS 파트 커스터마이징에 대해 더 알아보세요.

Dependencies

이 컴포넌트는 다음 의존성들을 자동으로 가져와요.

  • ``

더 알아보기 (Learn more)