버튼
버튼 (Button)
Quasar에는 QBtn이라는 버튼 컴포넌트가 있는데, 몇 가지 유용한 추가 기능을 가진 버튼이에요. 예를 들어 두 가지 모양이 있어요: 직사각형(기본)과 원형. 또한 material ripple 효과가 기본 내장돼 있어요(비활성화 가능).
출처: 문서
본문
Quasar에는 QBtn이라는 버튼 컴포넌트가 있는데, 몇 가지 유용한 추가 기능을 가진 버튼이에요. 예를 들어 두 가지 모양이 있어요: 직사각형(기본)과 원형. 그리고 material ripple 효과가 기본 내장돼 있어요(비활성화 가능).
버튼 컴포넌트에는 스피너 또는 로딩 효과도 있어요. 앱 실행이 지연을 일으키고 그 지연에 대해 사용자에게 피드백을 주고 싶을 때 사용하세요. 사용하면 사용자가 버튼을 클릭하는 즉시 회전 애니메이션을 표시해요.
비활성(disable)되거나 로딩 중이 아닐 때, QBtn은 클릭되거나 탭되면 즉시 @click 이벤트를 발생시켜요.
QBtn API
Props
size(string, optional) 단위 이름이나 표준 크기 이름(xs|sm|md|lg|xl)을 포함한 CSS 단위의 크기 예:'16px','2rem','xs','md'type(string, optional), default'button'- 버튼 네이티브 type 속성(submit, reset, button)을 정의하거나 2) disable일 때도 이벤트에 접근할 수 있도록 태그로 컴포넌트를 렌더링하거나 3) 'href' prop을 사용하고 'type'을 미디어 태그로 지정 예:
'a''submit''button''reset''image/png'href="https://quasar.dev" target="_blank"
to(string | object, optional) Vue Router 'to' 프로퍼티와 동일; 사용된다면 'href' prop이 우선 예:'/home/dashboard',{ name: 'my-route-name' }replace(boolean, optional) Vue Router 'replace' 프로퍼티와 동일; 사용된다면 'href' prop이 우선href(string, optional) 네이티브 링크 href 속성; 'to'와 'replace' props보다 우선 예:'https://quasar.dev',href="https://quasar.dev" target="_blank"target(string, optional) 네이티브 링크 target 속성; 'to'나 'href' props와 함께만 사용 예:'_blank','_self','_parent','_top'label(string | number, optional) 버튼에 표시될 텍스트 예:'Button Label'icon(string, optional) Quasar 규칙을 따르는 아이콘 이름; 'img:' 접두사를 쓰지 않는다면 아이콘 라이브러리가 설치되어 있어야 해요. 값으로 'none' (String)을 쓰면 아이콘이 렌더링되지 않아요(그래도 화면 공간은 차지해요) 예:'map','ion-add','img:https://cdn.quasar.dev/logo-v2/svg/logo.svg','img:path/to/some_image.png'icon-right(string, optional) Quasar 규칙을 따르는 아이콘 이름; 'img:' 접두사를 쓰지 않는다면 아이콘 라이브러리가 설치되어 있어야 해요. 값으로 'none' (String)을 쓰면 아이콘이 렌더링되지 않아요(그래도 화면 공간은 차지해요) 예:'map','ion-add','img:https://cdn.quasar.dev/logo-v2/svg/logo.svg','img:path/to/some_image.png'outline(boolean, optional) 'outline' 디자인 사용flat(boolean, optional) 'flat' 디자인 사용unelevated(boolean, optional) 그림자 제거rounded(boolean, optional) 정사각형 모양 버튼에 더 두드러진 border-radius 적용push(boolean, optional) 'push' 디자인 사용square(boolean, optional) border-radius를 제거해 모서리를 직각으로glossy(boolean, optional) 광택(glossy) 효과 적용fab(boolean, optional) 버튼 크기와 모양을 Floating Action Button에 맞게fab-mini(boolean, optional) 버튼 크기와 모양을 작은 Floating Action Button에 맞게padding(string, optional) 커스텀 padding 적용 (세로 [가로]); 단위 이름이나 표준 크기 이름(none|xs|sm|md|lg|xl)을 포함한 CSS 단위 크기; 설정하면 최소 넓이와 높이도 제거됨 예:'16px''10px 5px''2rem''xs''md lg''2px 2px 5px 7px'
color(string, optional) Quasar 색상 팔레트의 컴포넌트 색상 이름 예:'primary','teal','teal-10'text-color(string, optional) 텍스트 색상 오버라이드(필요 시); Quasar 색상 팔레트의 색상 이름 예:'primary','teal','teal-10'no-caps(boolean, optional) 라벨 텍스트를 대문자로 바꾸는 것(기본 동작) 방지no-wrap(boolean, optional) 라벨 텍스트 줄바꿈 방지dense(boolean, optional) Dense 모드; 공간을 덜 차지함ripple(boolean | object, optional), defaulttruematerial ripple 구성 ('false'로 설정하면 비활성화하거나 구성 객체를 제공) 예:false{ early: true, center: true, color: 'teal', keyCodes: [] }
tabindex(number | string, optional) Tabindex HTML 속성 값 예:100,'0'align(string, optional), default'center'라벨 또는 콘텐츠 정렬 허용값:'left','right','center','around','between','evenly'stack(boolean, optional) 아이콘과 라벨을 같은 줄 대신 세로로 쌓음(기본 동작)stretch(boolean, optional) flexbox 부모에서 사용할 때 버튼이 부모의 높이로 늘어남loading(boolean, optional), defaultnull버튼을 로딩 상태로 ('loading' 슬롯으로 오버라이드할 수 있는 QSpinner 표시)disable(boolean, optional) 컴포넌트를 disabled 모드로round(boolean, optional) 원형 버튼으로percentage(number, optional) 백분율 (0.0 < x < 100.0); 'loading' prop과 함께 사용; 배경에 진행률 바 표시dark-percentage(boolean, optional) 배경 진행률 바는 어두운 색이어야 함; 'percentage'와 'loading' props와 함께 사용
Methods
click(evt?: Event): voidQBtn에 클릭을 에뮬레이션 파라미터:evt(Event, optional) JS 이벤트 객체
Events
@click컴포넌트가 클릭될 때 발생 파라미터:evt(Event, optional) JS 이벤트 객체; 라우트 내비게이션('to'/'replace' props)을 사용하면서 내비게이션을 취소하고 싶다면 이벤트 핸들러에서 동기적으로 evt.preventDefault()를 호출해요go(Function, optional) 라우트 내비게이션('to'/'replace' props)을 사용할 때만 사용 가능; 컴포넌트가 라우트 내비게이션을 트리거할 시점을 제어해야 한다면 동기적으로 evt.preventDefault()를 호출한 뒤 원하는 때에 이 함수를 호출해요; 실제 라우트 내비게이션 전에 비동기 작업이 있거나 다른 곳으로 리다이렉트하고 싶을 때 유용 함수 시그니처:(opts?: object) => Promise<any>파라미터:opts(object, optional) 선택적 옵션 객체 형태:to(string | object, optional) Vue Router 'to' 프로퍼티와 동일; 명시적으로 지정하지 않으면 컴포넌트의 'to' prop과 같은 값으로 설정됨 예:'/home/dashboard',{ name: 'my-route-name' }replace(boolean, optional) Vue Router 'replace' 프로퍼티와 동일; 명시적으로 지정하지 않으면 컴포넌트의 'replace' prop과 같은 값으로 설정됨returnRouterError(boolean, optional) 라우터 오류가 있다면 반환; 그렇지 않으면 반환된 Promise는 항상 fulfill됨 반환값:Promise<any>라우터의 내비게이션 promise 반환
Slots
#default'icon'과 'label' props에 의존하는 대신 커스텀 콘텐츠에 사용#loading'loading' 상태일 때 기본 QSpinner를 오버라이드
Usage
Standard
"표준 버튼" 예시:
<template>
<div class="q-gutter-sm">
<q-btn color="white" text-color="black" label="Standard" />
<q-btn color="primary" label="Primary" />
<q-btn color="secondary" label="Secondary" />
<q-btn color="amber" glossy label="Amber" />
<q-btn color="brown-5" label="Brown 5" />
<q-btn color="deep-orange" glossy label="Deep Orange" />
<q-btn color="purple" label="Purple" />
<q-btn color="black" label="Black" />
</div>
</template>
커스텀 색상
<template>
<div class="q-gutter-sm">
<q-btn style="background: #ff0080; color: white" label="Fuchsia" />
<q-btn flat style="color: #ff0080" label="Fuchsia Flat" />
<q-btn style="background: goldenrod; color: white" label="Goldenrod" />
<q-btn outline style="color: goldenrod" label="Goldenrod" />
<q-btn
color="grey-4"
text-color="purple"
glossy
unelevated
icon="camera_enhance"
label="Purple text"
/>
</div>
</template>
아이콘과 함께
<template>
<div class="q-gutter-sm">
<q-btn color="primary" icon="mail" label="On Left" />
<q-btn color="secondary" icon-right="mail" label="On Right" />
<q-btn
color="red"
icon="mail"
icon-right="send"
label="On Left and Right"
/>
<br />
<q-btn icon="phone" label="Stacked" stack glossy color="purple" />
</div>
</template>
Round
"원형 버튼" 예시:
<template>
<div class="q-gutter-sm">
<q-btn round color="primary" icon="shopping_cart" />
<q-btn round color="secondary" icon="navigation" />
<q-btn round color="amber" glossy text-color="black" icon="layers_clear" />
<q-btn round color="brown-5" icon="directions" />
<q-btn round color="deep-orange" icon="edit_location" />
<q-btn round color="purple" glossy icon="local_grocery_store" />
<q-btn round color="black" icon="my_location" />
</div>
</template>
Square
"정사각형 버튼" 예시:
<template>
<div class="q-gutter-sm">
<q-btn square color="primary" icon="shopping_cart" />
<q-btn square color="secondary" icon="navigation" />
<q-btn square color="amber" glossy text-color="black" icon="layers_clear" />
<q-btn square color="brown-5" icon="directions" />
<q-btn square color="deep-orange" icon="edit_location" />
<q-btn square color="purple" glossy icon="local_grocery_store" />
<q-btn square color="black" icon="my_location" />
</div>
</template>
커스텀 콘텐츠
<template>
<div class="q-gutter-md">
<q-btn color="teal">
<q-icon left size="3em" name="map" />
<div>Label</div>
</q-btn>
<q-btn round>
<q-avatar size="42px">
<img alt="John Doe" src="https://cdn.quasar.dev/img/avatar2.jpg" />
</q-avatar>
</q-btn>
<q-btn color="indigo" no-caps> Multiline<br />Button </q-btn>
<q-btn color="deep-orange" push>
<div class="row items-center no-wrap">
<q-icon left name="map" />
<div class="text-center"> Custom<br />Content </div>
</div>
</q-btn>
</div>
</template>
"라벨 잘라내기" 예시:
<template>
<div class="q-gutter-sm">
<q-btn color="primary" style="width: 200px">
<div class="ellipsis">
This is some very long text that is expected to be truncated
</div>
</q-btn>
</div>
</template>
Design
"버튼 디자인" 예시:
<template>
<div class="q-gutter-sm">
<q-btn flat color="primary" label="Flat" />
<q-btn flat rounded color="primary" label="Flat Rounded" />
<q-btn flat round color="primary" icon="card_giftcard" />
<br />
<q-btn outline color="primary" label="Outline" />
<q-btn outline rounded color="primary" label="Outline Rounded" />
<q-btn outline round color="primary" icon="card_giftcard" />
<br />
<q-btn push color="primary" label="Push" />
<q-btn push color="primary" round icon="card_giftcard" />
<q-btn push color="white" text-color="primary" label="Push" />
<q-btn push color="white" text-color="primary" round icon="card_giftcard" />
<br />
<q-btn unelevated color="primary" label="Unelevated" />
<q-btn unelevated rounded color="primary" label="Unelevated Rounded" />
<q-btn unelevated round color="primary" icon="card_giftcard" />
<br />
<q-btn no-caps color="primary" label="No caps" />
<br />
<q-btn class="glossy" color="teal" label="Glossy" />
<q-btn class="glossy" rounded color="deep-orange" label="Glossy Rounded" />
<q-btn class="glossy" round color="primary" icon="card_giftcard" />
<q-btn class="glossy" round color="secondary" icon="local_florist" />
<q-btn class="glossy" round color="deep-orange" icon="local_activity" />
</div>
</template>
정렬
"버튼 정렬" 예시:
<template>
<div class="q-gutter-sm">
<q-btn
align="left"
class="btn-fixed-width"
color="primary"
label="Align to left"
/>
<q-btn
align="right"
class="btn-fixed-width"
color="secondary"
label="Align to right"
/>
<q-btn
align="between"
class="btn-fixed-width"
color="accent"
label="Align between"
icon="flight_takeoff"
/>
<q-btn
align="around"
class="btn-fixed-width"
color="brown-5"
label="Align around"
icon="lightbulb_outline"
/>
</div>
</template>
<style lang="sass" scoped>
.btn-fixed-width
width: 200px
</style>
Size
"버튼 크기" 예시:
<template>
<div class="q-gutter-sm">
<q-btn
v-for="size in sizes"
:key="`btn_size_sq_${size}`"
color="primary"
:size="size"
:label="`Size ${size}`"
/>
<br />
<q-btn
v-for="size in sizes"
:key="`btn_size_rd_${size}`"
rounded
color="primary"
:size="size"
:label="`Size ${size}`"
/>
<br />
<q-btn
v-for="(size, i) in sizes"
:key="`btn_size_round_${size}`"
round
color="primary"
:size="size"
:icon="icons[i]"
/>
<br />
<q-btn
v-for="size in sizes"
:key="`btn_size_dense_sq_${size}`"
dense
color="primary"
:size="size"
:label="`Size ${size}`"
/>
<br />
<q-btn
v-for="size in sizes"
:key="`btn_size_dense_rd_${size}`"
rounded
dense
color="primary"
:size="size"
:label="`Size ${size}`"
/>
<br />
<q-btn
v-for="(size, i) in sizes"
:key="`btn_size_dense_round_${size}`"
round
dense
color="primary"
:size="size"
:icon="icons[i]"
/>
<br />
<q-btn size="10px" color="black" label="Text height: 10px" />
<q-btn size="22px" class="q-px-xl q-py-xs" color="purple" label="Custom" />
<q-btn size="35px" round color="teal" icon="map" />
</div>
</template>
<script setup>
const sizes = ['xs', 'sm', 'md', 'lg', 'xl']
const icons = [
'navigation',
'add_a_photo',
'camera',
'camera_front',
'my_location'
]
</script>
Padding
기본 padding은 "xs md"예요. 하지만 padding prop으로 커스터마이즈할 수 있어요:
"버튼 padding" 예시:
<template>
<div class="q-gutter-sm">
<q-btn padding="none" color="primary" icon="eco" />
<q-btn padding="xs" color="primary" icon="eco" />
<q-btn padding="lg" color="primary" icon="eco" />
<q-btn padding="10px 5px" color="primary" icon="eco" />
<q-btn padding="xs lg" color="primary" icon="eco" />
<q-btn padding="xl" color="primary" round icon="eco" />
<q-btn padding="xs lg" color="primary" round icon="eco" />
<q-btn padding="lg xs" color="primary" round icon="eco" />
</div>
</template>
<script setup>
const sizes = ['xs', 'sm', 'md', 'lg', 'xl']
const icons = [
'navigation',
'add_a_photo',
'camera',
'camera_front',
'my_location'
]
</script>
진행률 관련
일부 버튼 액션은 서버와 통신하므로 비동기 응답이 필요해요. 비동기 응답이 준비될 때까지 진행 중인 백그라운드 프로세스에 대해 사용자에게 알리는 것이 가장 좋아요. QBtn은 loading prop으로 이 가능성을 제공해요. 이 프로퍼티는 버튼의 아이콘과/또는 라벨 대신 (기본적으로) QSpinner를 표시해요. 커스텀 로딩 콘텐츠도 사용할 수 있어요(텍스트나 스피너뿐만 아니라).
"불확정 진행률" 예시:
<template>
<div class="q-gutter-sm">
<q-btn
:loading="loading[0]"
color="secondary"
@click="simulateProgress(0)"
label="Button"
/>
<q-btn :loading="loading[1]" color="red" @click="simulateProgress(1)">
Button
<template #loading> Loading... </template>
</q-btn>
<q-btn :loading="loading[2]" color="purple" @click="simulateProgress(2)">
Button
<template #loading>
<q-spinner-radio />
</template>
</q-btn>
<q-btn
:loading="loading[3]"
color="primary"
@click="simulateProgress(3)"
style="width: 150px"
>
Button
<template #loading>
<q-spinner-hourglass class="on-left" />
Loading...
</template>
</q-btn>
<br />
<q-btn
round
:loading="loading[4]"
color="brown"
@click="simulateProgress(4)"
icon="camera_front"
>
<template #loading>
<q-spinner-facebook />
</template>
</q-btn>
<q-btn
round
:loading="loading[5]"
color="black"
@click="simulateProgress(5)"
icon="camera_rear"
>
<template #loading>
<q-spinner-gears />
</template>
</q-btn>
<br />
<q-btn :loading="progress" color="primary" @click="progress = true">
Controlled from outside
<template #loading>
<q-spinner-radio class="on-left" />
Click "Stop" Button
</template>
</q-btn>
<q-btn
:disable="!progress"
color="negative"
@click="progress = false"
label="Stop"
/>
</div>
</template>
<script setup>
import { ref } from 'vue'
const loading = ref([false, false, false, false, false, false])
const progress = ref(false)
function simulateProgress(number) {
// we set loading state
loading.value[number] = true
// simulate a delay
setTimeout(() => {
// we're done, we reset loading state
loading.value[number] = false
}, 3000)
}
</script>
원한다면 추가 percentage 프로퍼티를 진행 버튼에 대한 이미 배운 내용과 함께 사용해 버튼 안에 확정적(deterministic) 진행률을 표시할 수도 있어요:
"확정 진행률" 예시:
<template>
<div class="q-gutter-sm">
<q-btn
:loading="progress[0].loading"
:percentage="progress[0].percentage"
color="primary"
@click="startComputing(0)"
style="width: 150px"
>
Compute PI
<template #loading>
<q-spinner-gears class="on-left" />
Computing...
</template>
</q-btn>
<q-btn
:loading="progress[1].loading"
:percentage="progress[1].percentage"
round
color="secondary"
@click="startComputing(1)"
icon="cloud_upload"
/>
<q-btn
:loading="progress[2].loading"
:percentage="progress[2].percentage"
dark-percentage
unelevated
color="orange"
text-color="grey-9"
@click="startComputing(2)"
icon="cloud_upload"
style="width: 100px"
/>
</div>
</template>
<script setup>
import { onBeforeUnmount, ref } from 'vue'
const progress = ref([
{ loading: false, percentage: 0 },
{ loading: false, percentage: 0 },
{ loading: false, percentage: 0 }
])
const intervals = [null, null, null]
function startComputing(id) {
progress.value[id].loading = true
progress.value[id].percentage = 0
intervals[id] = setInterval(() => {
progress.value[id].percentage += Math.floor(Math.random() * 8 + 10)
if (progress.value[id].percentage >= 100) {
clearInterval(intervals[id])
progress.value[id].loading = false
}
}, 700)
}
onBeforeUnmount(() => {
intervals.forEach(val => {
clearInterval(val)
})
})
</script>
커스텀 ripple
<template>
<div class="q-gutter-sm">
<q-btn :ripple="false" color="secondary" label="No ripple" no-caps />
<q-btn
:ripple="{ color: 'yellow' }"
color="secondary"
label="Yellow ripple"
no-caps
/>
<q-btn
:ripple="{ center: true }"
color="secondary"
label="Center ripple"
no-caps
/>
</div>
</template>
Vue Router에 연결하기
[!IMPORTANT] UMD 사용
to&replaceprops를 사용할 예정이라면, 프로젝트에 Vue Router를 주입했는지 확인하세요 (Quasar CLI 프로젝트는 바로 제공돼요). 그렇지 않으면 대안인hrefprop을 사용하세요.- 위 이유로 아래 일부 QBtn은 Codepen/jsFiddle에서도 동작하지 않아요.
[!TIP] 가능하면
href보다 Vue Router props를 선호하세요.href를 쓰면 페이지 내 Vue Router 내비게이션 대신 window 내비게이션을 트리거하기 때문이에요.
"Links" 예시:
<template>
<div class="q-gutter-sm">
<q-btn
to="/start/pick-quasar-flavour"
label="To Docs index"
outline
color="purple"
/>
<q-btn
to="/start/pick-quasar-flavour"
label="To Docs index in 2s"
@click="linkClick"
glossy
color="purple"
/>
<q-btn
href="start/pick-quasar-flavour"
label="With href"
push
color="purple"
/>
<q-btn
href="start/pick-quasar-flavour"
target="_blank"
label="With href - open in new window"
color="purple"
/>
</div>
</template>
<script setup>
function linkClick(e, go) {
e.preventDefault() // we choose when we navigate
console.log('triggering navigation in 2s')
setTimeout(() => {
console.log('navigating as promised 2s ago')
go()
}, 2000)
}
</script>
아래처럼 내비게이션을 지연, 취소 또는 리다이렉트할 수도 있어요. 아래에서 사용된 @click 이벤트에 대한 더 자세한 설명은 페이지 상단의 QBtn API 카드를 참조하세요.
"지연, 취소 또는 리다이렉트된 내비게이션을 가진 링크" 예시:
<template>
<div class="q-gutter-sm">
<q-btn
to="/"
label="Delayed navigation"
@click="onDelayedClick"
outline
color="purple"
no-caps
/>
<q-btn
to="/"
label="Cancelled navigation"
@click="onCancelledClick"
glossy
color="purple"
no-caps
/>
<q-btn
to="/"
label="Redirected navigation"
@click="onRedirectedClick"
glossy
color="purple"
no-caps
/>
</div>
</template>
<script setup>
function onDelayedClick(e, go) {
e.preventDefault() // mandatory; we choose when we navigate
console.log('triggering navigation in 2s')
setTimeout(() => {
console.log('navigating as promised 2s ago')
go()
}, 2000)
}
function onCancelledClick(e, go) {
e.preventDefault() // mandatory; we choose when we navigate
// then we never call go()
}
function onRedirectedClick(e, go) {
e.preventDefault() // mandatory; we choose when we navigate
// call this at your convenience
go({
to: '/start/pick-quasar-flavour' // we pick another route
// replace: boolean; default is what the tab is configured with
// returnRouterError: boolean
})
.then(_vueRouterResult => {
/* ... */
})
.catch(_vueRouterError => {
/* ...will not reach here unless returnRouterError === true */
})
}
</script>
더 복잡한 사용 사례를 위해, 네이티브 Vue <router-link> 컴포넌트를 사용해 QBtn을 직접 감쌀 수도 있어요. 이는 또한 앱의 현재 라우트에 따라 상태를 제어할 기회도 줘요:
"RouterLink의 Scoped slot" 예시:
<template>
<div class="column q-gutter-sm">
<router-link :to="{ hash: '#Handling-links' }" custom #default="props">
<q-btn v-bind="buttonProps(props)" />
</router-link>
<router-link
:to="{ hash: '#Handling-links', query: { search: '1' } }"
custom
#default="props"
>
<q-btn v-bind="buttonProps(props)" />
</router-link>
<router-link
:to="{ hash: '#Handling-links', query: { search: '1', test: '1' } }"
custom
#default="props"
>
<q-btn v-bind="buttonProps(props)" />
</router-link>
<router-link
:to="{ hash: '#Handling-links', query: { search: '1', test: '2' } }"
custom
#default="props"
>
<q-btn v-bind="buttonProps(props)" />
</router-link>
<router-link
:to="{ hash: '#Handling-links', query: { search: '1', test: '1' } }"
custom
#default="props"
>
<q-btn
v-bind="buttonProps(props)"
icon-right="timer_3"
@click="linkClick"
/>
</router-link>
</div>
</template>
<script setup>
function linkClick(e, go) {
e.preventDefault() // we choose when we navigate
console.log('triggering navigation in 3s')
setTimeout(() => {
console.log('navigating as promised 3s ago')
go()
}, 3000)
}
function buttonProps({ href, route, isActive, isExactActive }) {
const props = {
color: 'black',
noCaps: true,
label: `To "${route.fullPath}"`,
outline: true,
to: href
}
if (isActive) {
props.color = isExactActive ? 'primary' : 'amber-9'
} else {
props.color = 'black'
}
return props
}
</script>
기타 옵션
<template>
<q-btn color="black" class="full-width" label="Full-width" />
<q-btn color="primary" label="With Tooltip" class="q-mt-md">
<q-tooltip class="bg-accent">I'm a tooltip</q-tooltip>
</q-btn>
</template>
Disable
<template>
<div class="q-gutter-sm">
<q-btn color="primary" disable label="Disabled" />
<q-btn round color="primary" disable icon="card_giftcard" />
<q-btn flat color="primary" disable label="Disabled" />
<q-btn flat round color="primary" disable icon="card_giftcard" />
<q-btn outline color="primary" disable label="Disabled" />
<q-btn outline round color="primary" disable icon="card_giftcard" />
<q-btn push color="primary" disable label="Disabled" />
<q-btn push round color="primary" disable icon="card_giftcard" />
<q-btn class="glossy" color="primary" disable label="Disabled" />
<q-btn class="glossy" round color="primary" disable icon="card_giftcard" />
</div>
</template>
폼 제출을 위한 버튼 제어
"Save" 버튼처럼 폼의 입력을 서버로 제출하는 버튼이 있을 때, ENTER 키를 눌러 폼을 제출할 수 있는 기능을 사용자에게 주고 싶을 때가 많아요. 진행 중인 저장 과정에 대한 피드백을 주고, 사용자가 버튼을 반복해서 누르는 것을 방지하고 싶다면, 버튼에 로딩 스피너를 표시하고 클릭 이벤트에서 비활성화해야 해요. QBtn은 이렇게 설정하면 이 동작을 허용해요.
[!IMPORTANT] type이 "submit"인 QBtn을 QField, QInput 또는 QSelect의 "before", "after", "prepend", "append" 슬롯 중 하나에 배치할 때는, 해당 QBtn에
@click리스너도 추가해야 해요. 이 리스너는 폼을 제출하는 메서드를 호출해야 해요. 이러한 슬롯의 모든 "click" 이벤트는 부모 요소로 전파되지 않아요.
"Form Submission" 예시:
<template>
<form @submit.prevent="simulateSubmit" class="q-pa-md">
<!-- a simple text field watching for the enter key release -->
<q-input
filled
color="teal"
hint="Type then hit Enter key above"
v-model="test"
/>
<!--
A button with v-model set to submit.
v-model scope variable must be a strict Boolean
-->
<div class="row justify-end">
<q-btn
type="submit"
:loading="submitting"
label="Save"
class="q-mt-md"
color="teal"
>
<template #loading>
<q-spinner-facebook />
</template>
</q-btn>
</div>
</form>
</template>
<script setup>
import { ref } from 'vue'
const test = ref('')
const submitting = ref(false)
function simulateSubmit() {
submitting.value = true
// Simulating a delay here.
// When we are done, we reset "submitting"
// Boolean to false to restore the
// initial state.
setTimeout(() => {
// delay simulated, we are done,
// now restoring submit to its initial state
submitting.value = false
}, 3000)
}
</script>
Accessibility (v2.25+)
QBtn은 네이티브 <button> 요소로 렌더링되거나, 링크(href, to 또는 type="a")로 동작할 때 <a>로 렌더링돼요; 결국 href 없이 끝난 링크 버튼은 role="button"을 받아 여전히 버튼으로 알려져요. 링크 버튼에서 QBtn은 Space에서도 활성화를 합성해요 — 네이티브 <a>는 Enter에만 반응하니까요 — 그래서 렌더링된 태그와 무관하게 두 키 모두 동작해요.
disable 또는 loading 상태 동안 버튼은 aria-disabled="true"로 표시되고 탭 순서에서 빠지며(비활성 non-link 버튼은 네이티브 disabled 속성도 받아요), 로딩 버튼은 안정될 때까지 모든 상호작용을 삼켜요. percentage prop으로 로딩할 때 버튼은 progressbar로 노출되고 aria-valuenow를 통해 진행률을 알려줘요.
QBtn에는 전용 aria-label prop이 없지만, 속성은 렌더링된 요소로 전달돼요 — 그렇지 않으면 접근 가능한 이름이 없는 아이콘 전용(예: round) 버튼에는 반드시 제공하세요. 버튼 안의 QTooltip은 이를 대신하지 못해요: 버튼의 description(aria-describedby)이 되지 절대 이름이 안 되므로, 유일한 텍스트가 툴팁인 아이콘 전용 버튼은 여전히 이름 없는 버튼으로 알려져요.
더 알아보기 (Learn more)
QBtn은 직사각형/원형 모양에 material ripple이 내장된 범용 버튼 컴포넌트예요. flat/outline/push/glossy/unelevated 등 다양한 디자인, size/padding/color/align, 아이콘(icon/icon-right, stack), loading(스피너·확정 percentage 진행률)을 지원해요. to/href로 라우트·링크 연결하고, disable로 비활성화, @click에서 go()로 내비게이션을 제어할 수 있어요.