Checkbox
Checkbox (체크박스)
출처: 문서
본문
Checkbox
여러 개를 선택할 수 있는 옵션 그룹이에요.
WARNING
label을 값으로 사용하는 것은 더 이상 사용되지 않으며(Deprecated),label은 표시 텍스트로만 사용돼요. 이 동작은 3.0.0에서 제거될 예정이에요. 새 API로 전환하는 것을 고려해 주세요.
TIP 새 API
value는 2.6.0에 추가됐어요. 문서의 예시는 모두value를 사용해요. 2.6.0보다 낮은 버전을 사용하면서 checkbox-group을 사용한다면 다음을 참고해 주세요.
기본 사용법
Checkbox를 단독으로 사용해서 두 상태 사이를 전환할 수 있어요.
el-checkbox에 v-model(바인딩 변수)을 정의해요. 단일 체크박스의 기본값은 Boolean이며, 선택되면 true가 돼요. el-checkbox 태그 안의 내용은 체크박스 버튼 뒤의 설명이 돼요.
import { ref } from 'vue'
const checked1 = ref(true)
const checked2 = ref(false)
const checked3 = ref(false)
const checked4 = ref(false)
const checked5 = ref(false)
const checked6 = ref(false)
비활성화 상태
체크박스의 비활성화 상태예요.
disabled 속성을 설정해요.
Checkbox group
하나의 그룹에 바인딩된 여러 체크박스에 사용되며, 체크 여부를 통해 한 옵션이 선택되었는지 나타내요.
checkbox-group 요소는 Array로 바인딩되는 v-model을 사용해서 하나의 그룹 안에서 여러 체크박스를 관리할 수 있어요. el-checkbox 요소 안에서 value는 체크박스의 값이에요. 태그 안에 내용이 없으면 label이 체크박스 버튼 뒤의 설명으로 렌더링돼요. value는 배열의 요소 값과도 대응해요. 지정된 값이 배열에 존재하면 선택되고, 그 반대도 마찬가지예요.
Options 속성 2.11.2
기본 el-checkbox-group 사용법의 단축형이에요. props 속성을 통해 options의 별칭을 커스터마이즈할 수 있어요.
Indeterminate (불확정)
indeterminate 속성은 '전체 선택' 효과를 구현하는 데 도움을 줘요.
최소 / 최대 선택 항목
min과 max 속성은 선택된 항목 수를 제한하는 데 도움을 줘요.
버튼 스타일
버튼 스타일의 Checkbox예요.
el-checkbox 요소를 el-checkbox-button 요소로 바꾸면 돼요. size 속성도 제공돼요.
import { ref } from 'vue'
const checkboxGroup1 = ref(['Shanghai'])
const checkboxGroup2 = ref(['Shanghai'])
const checkboxGroup3 = ref(['Shanghai'])
const checkboxGroup4 = ref(['Shanghai'])
const cities = ['Shanghai', 'Beijing', 'Guangzhou', 'Shenzhen']
.demo-button-style {
margin-top: 24px;
}
테두리와 함께
border 속성이 Checkbox에 테두리를 추가해요.
import { ref } from 'vue'
const checked1 = ref(true)
const checked2 = ref(false)
const checked3 = ref(false)
const checked4 = ref(true)
const checkboxGroup1 = ref(['Value1'])
Checkbox API
Checkbox Attributes
| Name | Description | Type | Default |
|---|---|---|---|
| model-value / v-model | 바인딩 값 | string / number / boolean | — |
| value 2.6.0 | checkbox-group 안에서 사용할 때 Checkbox의 값 | string / number / boolean / object | — |
| label | checkbox-group 안에서 사용할 때 Checkbox의 label. value가 없으면 label이 값으로 동작해요 | string / number / boolean / object | — |
| true-value 2.6.0 | 체크되었을 때의 Checkbox 값 | string / number | — |
| false-value 2.6.0 | 체크되지 않았을 때의 Checkbox 값 | string / number | — |
| disabled | Checkbox 비활성화 여부 | boolean | false |
| border | Checkbox 주위에 테두리를 추가할지 여부 | boolean | false |
| size | Checkbox의 크기 | enum | — |
| name | 네이티브 'name' 속성 | string | — |
| checked | Checkbox 체크 여부 | boolean | false |
| indeterminate | Indeterminate 상태 설정, 스타일 제어만 담당 | boolean | false |
| validate-event | 폼 검증 트리거 여부 | boolean | true |
| tabindex | input tabindex | string / number | — |
| id | input id | string | — |
| aria-controls a11y 2.7.2 | aria-controls와 동일, indeterminate가 true일 때 적용 | string | — |
| aria-label a11y | 네이티브 aria-label 속성 | string | — |
| true-label deprecated | 체크되었을 때의 Checkbox 값 | string / number | — |
| false-label deprecated | 체크되지 않았을 때의 Checkbox 값 | string / number | — |
| controls a11y deprecated | aria-controls와 동일, indeterminate가 true일 때 적용 | string | — |
Checkbox Events
| Name | Description | Type |
|---|---|---|
| change | 바인딩 값이 변경될 때 실행돼요 | Function |
Checkbox Slots
| Name | Description |
|---|---|
| default | 기본 내용을 커스터마이즈해요 |
CheckboxGroup API
CheckboxGroup Attributes
| Name | Description | Type | Default |
|---|---|---|---|
| model-value / v-model | 바인딩 값 | array | [] |
| size | checkbox 크기 | enum | — |
| disabled | 중첩된 checkbox 비활성화 여부 | boolean | false |
| min | 체크된 checkbox의 최소 개수 | number | — |
| max | 체크된 checkbox의 최대 개수 | number | — |
| aria-label a11y 2.7.2 | 네이티브 aria-label 속성 | string | — |
| text-color | 버튼 활성 상태의 글꼴 색상 | string | #ffffff |
| fill | 버튼 활성 상태의 테두리 및 배경 색상 | string | #409eff |
| tag | checkbox 그룹의 요소 태그 | string | div |
| validate-event | 폼 검증 트리거 여부 | boolean | true |
| label a11y deprecated | 네이티브 aria-label 속성 | string | — |
| options 2.11.2 | options의 데이터, value와 label, disabled의 키는 props로 커스터마이즈 가능 | array | — |
| props 2.11.2 | 구성 옵션 | object | {value: 'value', label: 'label', disabled: 'disabled'} |
| type 2.11.5 | options를 렌더링할 컴포넌트 타입 (예: 'button') | enum | 'checkbox' |
CheckboxGroup Events
| Name | Description | Type |
|---|---|---|
| change | 바인딩 값이 변경될 때 실행돼요 | Function |
CheckboxGroup Slots
| Name | Description | Subtags |
|---|---|---|
| default | 기본 내용을 커스터마이즈해요 | Checkbox / Checkbox-button |
CheckboxButton API
CheckboxButton Attributes
| Name | Description | Type | Default |
|---|---|---|---|
| value 2.6.0 | checkbox-group 안에서 사용할 때 checkbox의 값 | string / number / boolean / object | — |
| label | checkbox-group 안에서 사용할 때 checkbox의 label. value가 없으면 label이 값으로 동작해요 | string / number / boolean / object | — |
| true-value 2.6.0 | 체크되었을 때의 checkbox 값 | string / number | — |
| false-value 2.6.0 | 체크되지 않았을 때의 checkbox 값 | string / number | — |
| disabled | checkbox 비활성화 여부 | boolean | false |
| name | 네이티브 'name' 속성 | string | — |
| checked | checkbox 체크 여부 | boolean | false |
| true-label deprecated | 체크되었을 때의 checkbox 값 | string / number | — |
| false-label deprecated | 체크되지 않았을 때의 checkbox 값 | string / number | — |
CheckboxButton Slots
| Name | Description |
|---|---|
| default | 기본 내용을 커스터마이즈해요 |