FloatButton 懸浮按鈕
頁面上的圓形或圓角方形浮動按鈕,常置於右下角,提供說明、回饋或新增等全域操作。可搭配文字提示、徽章與子按鈕選單,也可使用 HuiFloatButtonGroup 垂直組合。
引入
import { HuiFloatButton, HuiFloatButtonGroup } from '@nscode/handy-ui'
基礎用法
icon 是圖示名,tooltip 是懸停或聚焦時的文字提示(預設顯示在左邊)。預設 position="fixed",用 right、bottom 等定位,數值以 px,字串原樣使用(如 '10%')。
為了將效果限制在預覽框內,本頁使用 position="absolute"(相對設有 position: relative 的預覽框定位)或 position="relative"(保留原位置並參與排列)。三種定位方式的差異見下一節。
<script setup lang="ts">
import { HuiFloatButton, HuiMessage } from '@nscode/handy-ui'
const openHelp = () => {
HuiMessage.info('打開說明中心')
}
</script>
<template>
<div class="stage">
<HuiFloatButton
icon="help"
tooltip="說明中心"
position="absolute"
:right="24"
:bottom="24"
@click="openHelp"
/>
</div>
</template>
<style scoped>
.stage {
position: relative;
height: 120px;
border: 1px dashed var(--hui-border-color);
border-radius: var(--hui-border-radius);
background-color: var(--hui-bg-color-page);
}
</style>
僅含圖示時,按鈕的無障礙名稱 aria-label 取自 tooltip。因此須提供 tooltip 或明確指定 aria-label,否則開發環境會在主控台警告。
定位方式
position 可選:
fixed(預設):固定在瀏覽器視窗上,不隨頁面捲動。z-index 跟隨HuiConfigProvider的zIndex(預設 2000)。absolute:相對最近的定位祖先(position不是static的元素),配合left、right、top、bottom放在某個區域的角落。relative:留在原來的位置,和前後的內容排在一起,left等是相對原位置的偏移。
打開開關後,fixed 的按鈕出現在瀏覽器視窗的右下角:
<script setup lang="ts">
import { ref } from 'vue'
import { HuiFloatButton, HuiSpace, HuiSwitch } from '@nscode/handy-ui'
const showFixed = ref(false)
</script>
<template>
<HuiSpace direction="vertical" fill>
<HuiSwitch v-model="showFixed" active-text="顯示 fixed 按鈕(視窗右下角)" />
<div class="stage">
<HuiSpace>
<span>relative,留在原位置:</span>
<HuiFloatButton icon="star" tooltip="relative" position="relative" />
</HuiSpace>
<HuiFloatButton
icon="bell"
tooltip="absolute,在範例框右下角"
type="primary"
position="absolute"
:right="24"
:bottom="24"
/>
</div>
</HuiSpace>
<HuiFloatButton
v-if="showFixed"
icon="heart"
tooltip="fixed,固定在視窗右下角"
type="primary"
:right="40"
:bottom="40"
/>
</template>
<style scoped>
.stage {
position: relative;
height: 120px;
padding: 16px;
border: 1px dashed var(--hui-border-color);
border-radius: var(--hui-border-radius);
background-color: var(--hui-bg-color-page);
}
</style>
類型與形狀
type:default(白底,預設)或primary(主色底、白色圖示)。shape:circle(圓形,預設)或square(圓角方形,圓角 8px)。
<template>
<HuiSpace size="large">
<HuiFloatButton icon="help" tooltip="default + circle" position="relative" />
<HuiFloatButton icon="plus" type="primary" tooltip="primary + circle" position="relative" />
<HuiFloatButton icon="bell" shape="square" tooltip="default + square" position="relative" />
<HuiFloatButton
icon="edit"
type="primary"
shape="square"
tooltip="primary + square"
position="relative"
/>
</HuiSpace>
</template>
文字提示的位置
tooltip-placement 是文字提示的位置,預設 left,可選 12 個方向,放不下時自動翻到另一側。把滑鼠移到下面的按鈕上看效果,按鈕下面的小字是方向:
<template>
<HuiSpace direction="vertical" align="start">
<HuiSpace wrap>
<HuiFloatButton
shape="square"
icon="arrow-up"
description="top"
tooltip="top"
tooltip-placement="top"
position="relative"
:width="96"
/>
<HuiFloatButton
shape="square"
icon="arrow-up"
description="top-start"
tooltip="top-start"
tooltip-placement="top-start"
position="relative"
:width="96"
/>
<HuiFloatButton
shape="square"
icon="arrow-up"
description="top-end"
tooltip="top-end"
tooltip-placement="top-end"
position="relative"
:width="96"
/>
<HuiFloatButton
shape="square"
icon="arrow-down"
description="bottom"
tooltip="bottom"
tooltip-placement="bottom"
position="relative"
:width="96"
/>
<HuiFloatButton
shape="square"
icon="arrow-down"
description="bottom-start"
tooltip="bottom-start"
tooltip-placement="bottom-start"
position="relative"
:width="96"
/>
<HuiFloatButton
shape="square"
icon="arrow-down"
description="bottom-end"
tooltip="bottom-end"
tooltip-placement="bottom-end"
position="relative"
:width="96"
/>
</HuiSpace>
<HuiSpace wrap>
<HuiFloatButton
shape="square"
icon="arrow-left"
description="left"
tooltip="left"
tooltip-placement="left"
position="relative"
:width="96"
/>
<HuiFloatButton
shape="square"
icon="arrow-left"
description="left-start"
tooltip="left-start"
tooltip-placement="left-start"
position="relative"
:width="96"
/>
<HuiFloatButton
shape="square"
icon="arrow-left"
description="left-end"
tooltip="left-end"
tooltip-placement="left-end"
position="relative"
:width="96"
/>
<HuiFloatButton
shape="square"
icon="arrow-right"
description="right"
tooltip="right"
tooltip-placement="right"
position="relative"
:width="96"
/>
<HuiFloatButton
shape="square"
icon="arrow-right"
description="right-start"
tooltip="right-start"
tooltip-placement="right-start"
position="relative"
:width="96"
/>
<HuiFloatButton
shape="square"
icon="arrow-right"
description="right-end"
tooltip="right-end"
tooltip-placement="right-end"
position="relative"
:width="96"
/>
</HuiSpace>
</HuiSpace>
</template>
描述文字和尺寸
description 顯示於圖示下方,字級為 12px,通常搭配 shape="square";有說明文字時,圖示由 20px 縮至 16px。40px 寬按鈕可容納兩個中文字,過長時顯示省略號,可透過 width 加寬。width、height 預設均為 40,數值以 px 計,字串原樣使用;內容放不下時會自動增高。description 插槽可自訂內容,優先於同名屬性。
預設插槽可以放自訂圖示或文字,明確指定預設插槽時不顯示 icon。
<template>
<HuiSpace size="large" align="end">
<HuiFloatButton shape="square" icon="mail" description="反饋" position="relative" />
<HuiFloatButton
shape="square"
icon="phone"
description="電話客服(被截斷)"
position="relative"
/>
<HuiFloatButton
shape="square"
icon="phone"
description="電話客服"
:width="64"
:height="56"
position="relative"
/>
<HuiFloatButton shape="square" icon="user" width="4rem" height="4rem" position="relative">
<template #description>
<span style="color: var(--hui-color-primary)">我的</span>
</template>
</HuiFloatButton>
<HuiFloatButton tooltip="AI 助手" position="relative">
<span style="font-weight: 600">AI</span>
</HuiFloatButton>
<HuiFloatButton
tooltip="大按鈕"
icon="plus"
type="primary"
:width="56"
:height="56"
position="relative"
/>
</HuiSpace>
</template>
角標
badge 在右上角顯示角標(用的是 HuiBadge):
- 數字或字串:顯示內容,數字超過 99 顯示
99+; true,或者只寫badge:顯示小圓點;false、0:不顯示。要顯示 0 時傳字串'0'。
圓形按鈕的角標貼著圓的邊(對準右上方 45° 的位置),方形按鈕的對準外框的角。
<script setup lang="ts">
import { ref } from 'vue'
import { HuiButton, HuiFloatButton, HuiSpace } from '@nscode/handy-ui'
const unread = ref(5)
</script>
<template>
<HuiSpace direction="vertical" align="start" size="large">
<HuiSpace size="large">
<HuiFloatButton icon="bell" tooltip="通知" :badge="unread" position="relative" />
<HuiFloatButton icon="user" tooltip="新動態" badge position="relative" />
<HuiFloatButton icon="mail" tooltip="99+" :badge="120" position="relative" />
<HuiFloatButton icon="star" tooltip="文字角標" badge="new" position="relative" />
<HuiFloatButton icon="file" tooltip="字串 '0'" badge="0" position="relative" />
<HuiFloatButton icon="folder" tooltip="數字 0 不顯示" :badge="0" position="relative" />
<HuiFloatButton
icon="bell"
shape="square"
tooltip="方形按鈕"
:badge="unread"
position="relative"
/>
</HuiSpace>
<HuiSpace>
<HuiButton size="small" @click="unread++">未讀 +1</HuiButton>
<HuiButton size="small" @click="unread = 0">清空(0 時不顯示)</HuiButton>
</HuiSpace>
</HuiSpace>
</template>
徽章不納入按鈕的無障礙名稱,螢幕閱讀器不會讀出。若需朗讀數量,請加入 aria-label,例如 :aria-label="'通知,' + unread + ' 則未讀'"。
連結
明確指定 href 就渲染成 <a>,target="_blank" 時自動加 rel="noopener noreferrer"(自己明確指定 rel 時用自己的)。
<template>
<HuiSpace size="large">
<HuiFloatButton
icon="link"
tooltip="使用手冊(新視窗打開)"
href="https://example.com/manual"
target="_blank"
position="relative"
/>
<HuiFloatButton
icon="download"
shape="square"
description="下載"
href="https://example.com/download"
target="_blank"
position="relative"
/>
</HuiSpace>
</template>
展開選單
menu 插槽裡放幾個 HuiFloatButton,它們豎著排在主按鈕上方,點主按鈕展開、再點收合;展開時主按鈕的圖示換成關閉圖示(close)。
menu-trigger="click"(預設):點擊展開、再點收合;在頁面其他地方按下滑鼠、或者焦點移到別處時收合。menu-trigger="hover":滑鼠移入展開,移出 100ms 後收合;滑鼠移到子按鈕上不收合。點擊主按鈕也能展開(觸控設備沒有懸停),但不會收合。- 用
v-model:visible讀寫展開狀態。 - 點了子按鈕選單不收合,要收合時把
visible改成false。
子按鈕不用寫 position、right 等,由選單排列;shape 不寫時跟隨主按鈕。下面左邊是點擊展開,右邊是懸停展開(方形,子按鈕跟隨變方形):
<script setup lang="ts">
import { ref } from 'vue'
import { HuiFloatButton, HuiMessage } from '@nscode/handy-ui'
const open = ref(false)
const hoverOpen = ref(false)
const create = (kind: string) => {
open.value = false
HuiMessage.success(`新建${kind}`)
}
</script>
<template>
<div class="stage">
<p class="state">
點擊選單:{{ open ? '展開' : '收合' }};懸停選單:{{ hoverOpen ? '展開' : '收合' }}
</p>
<HuiFloatButton
v-model:visible="open"
type="primary"
icon="plus"
tooltip="新建"
menu-trigger="click"
position="absolute"
:left="40"
:bottom="24"
>
<template #menu>
<HuiFloatButton icon="file" tooltip="新建文件" @click="create('文件')" />
<HuiFloatButton icon="folder" tooltip="新建資料夾" @click="create('資料夾')" />
<HuiFloatButton icon="table" tooltip="新建表格" @click="create('表格')" />
</template>
</HuiFloatButton>
<HuiFloatButton
v-model:visible="hoverOpen"
shape="square"
icon="share"
tooltip="分享"
menu-trigger="hover"
position="absolute"
:left="120"
:bottom="24"
>
<template #menu>
<HuiFloatButton icon="mail" tooltip="郵件分享" />
<HuiFloatButton icon="link" tooltip="複製連結" />
</template>
</HuiFloatButton>
</div>
</template>
<style scoped>
.stage {
position: relative;
height: 260px;
border: 1px dashed var(--hui-border-color);
border-radius: var(--hui-border-radius);
background-color: var(--hui-bg-color-page);
}
.state {
margin: 0;
padding: 12px 16px;
color: var(--hui-text-color-secondary);
}
</style>
按鈕群組
HuiFloatButtonGroup 把幾個懸浮按鈕豎著排成一組,組負責定位(position、left、right、top、bottom,規則同 HuiFloatButton),群組中的按鈕自己的 position、right 等不生效。
shape="circle"(預設):圓形按鈕,之間隔 16px,各自帶陰影。shape="square":方形按鈕連成一整塊,按鈕之間是一條分隔線,陰影和外圓角在組上。
群組中按鈕的形狀統一跟隨組的 shape,按鈕自行指定的 shape 不生效。下面左邊是 circle,右邊是 square:
<script setup lang="ts">
import { HuiFloatButton, HuiFloatButtonGroup, HuiMessage } from '@nscode/handy-ui'
const notify = (text: string) => {
HuiMessage.info(text)
}
</script>
<template>
<div class="stage">
<HuiFloatButtonGroup position="absolute" :left="40" :bottom="24" aria-label="快捷操作">
<HuiFloatButton icon="help" tooltip="說明" @click="notify('說明')" />
<HuiFloatButton icon="mail" tooltip="反饋" :badge="2" @click="notify('反饋')" />
<HuiFloatButton icon="arrow-up" tooltip="頂端" @click="notify('回到頂端')" />
</HuiFloatButtonGroup>
<HuiFloatButtonGroup
position="absolute"
:left="120"
:bottom="24"
shape="square"
aria-label="快捷操作"
>
<HuiFloatButton icon="help" description="說明" @click="notify('說明')" />
<HuiFloatButton icon="mail" description="反饋" :badge="2" @click="notify('反饋')" />
<HuiFloatButton icon="arrow-up" description="頂端" @click="notify('回到頂端')" />
</HuiFloatButtonGroup>
</div>
</template>
<style scoped>
.stage {
position: relative;
height: 220px;
border: 1px dashed var(--hui-border-color);
border-radius: var(--hui-border-radius);
background-color: var(--hui-bg-color-page);
}
</style>
組的根元素是 role="group",可以寫 aria-label="快捷操作" 給螢幕閱讀器一個名稱。
和回到頂端一起用
單獨的回到頂端按鈕用 HuiBacktop:它自己監聽捲動,滾過 visibility-height 才出現,外觀(40×40 的圓、邊框、陰影、圖示大小)和 HuiFloatButton 一致。兩個按鈕分開放時錯開位置即可,例如 HuiBacktop 在 bottom: 40,懸浮按鈕在 bottom: 96。
HuiBacktop 自行採用 fixed 定位,不可直接放入 HuiFloatButtonGroup,否則仍會依自身 right、bottom 固定於視口,不參與群組排列。群組內若需要回到頂端,請組合 HuiFloatButton、icon="arrow-up" 並自行判斷捲動位置。下例向下捲動超過 200px 後,群組會顯示回到頂端按鈕。
<script setup lang="ts">
import { ref } from 'vue'
import { HuiFloatButton, HuiFloatButtonGroup } from '@nscode/handy-ui'
const boxRef = ref<HTMLElement>()
const showTop = ref(false)
// 監聽頁面捲動時換成 window.scrollY 和 window.addEventListener('scroll', ...)
const update = () => {
showTop.value = (boxRef.value?.scrollTop ?? 0) >= 200
}
const toTop = () => boxRef.value?.scrollTo({ top: 0, behavior: 'smooth' })
</script>
<template>
<div class="stage">
<div ref="boxRef" class="box" @scroll="update">
<p v-for="i in 30" :key="i" class="line">第 {{ i }} 行內容</p>
</div>
<HuiFloatButtonGroup position="absolute" :right="24" :bottom="16">
<HuiFloatButton icon="help" tooltip="說明" />
<HuiFloatButton v-if="showTop" icon="arrow-up" tooltip="回到頂端" @click="toTop" />
</HuiFloatButtonGroup>
</div>
</template>
<style scoped>
.stage {
position: relative;
}
.box {
height: 240px;
overflow: auto;
padding: 0 16px;
border: 1px solid var(--hui-border-color);
border-radius: var(--hui-border-radius);
}
.line {
margin: 12px 0;
color: var(--hui-text-color-secondary);
}
</style>
聚焦和失焦
通過 ref 呼叫 focus()、blur() 讓主按鈕獲得、失去焦點,聚焦時會顯示文字提示。
<script setup lang="ts">
import { ref } from 'vue'
import { HuiButton, HuiFloatButton, HuiSpace } from '@nscode/handy-ui'
const fabRef = ref<InstanceType<typeof HuiFloatButton>>()
</script>
<template>
<HuiSpace size="large">
<HuiButton @click="fabRef?.focus()">聚焦</HuiButton>
<HuiButton @click="fabRef?.blur()">失焦</HuiButton>
<HuiFloatButton
ref="fabRef"
icon="setting"
tooltip="聚焦時顯示提示"
tooltip-placement="right"
position="relative"
/>
</HuiSpace>
</template>
鍵盤操作
- 主按鈕是原生
<button>(有href時是<a>),Tab 能聚焦,聚焦時顯示文字提示;<button>Enter、空白觸發,<a>Enter觸發。 - 有選單時:Enter、空白展開選單,焦點移到第一個子按鈕,再按一次收合;在主按鈕上按向上鍵展開並聚焦離主按鈕最近的(最下面的)子按鈕,向下鍵聚焦第一個。
- 選單中可用上下鍵循環切換可用子按鈕,以 Home / End 移至首末項目。每層僅保留一個 Tab 停留點,按 Tab 離開時收合。輸入法組字、鍵碼 229 與 Ctrl / Meta / Alt 組合鍵不會移動選單焦點。
- Esc 收合選單並將焦點還給主按鈕。位於對話框或抽屜內時,這次 Esc 只處理選單,不連帶關閉外層。
祖先尺寸變數與明確屬性
--hui-float-button-width、--hui-float-button-height 可設定於按鈕或任一祖先。實際尺寸依明確 width/height → 公開變數 → 原 40px 預設值讀取。高度仍為最小高度,說明文字較多時可自動增高;數值、CSS 長度與純數字字串沿用原轉換規則。
下例外層統一64px/52px,內層局部覆蓋36px/36px;中間按鈕同時設定自身60px/56px和明確48px/40px,優先使用屬性。撤銷屬性後回到自身變數,再次啟用恢復屬性尺寸。圓形角標與按鈕讀取同一最終寬高,保留原圓周45°偏移算法;選單子按鈕重設私有屬性覆蓋,不會串用主按鈕的明確屬性。按鈕群組與選單的原定位、形狀和交互規則保持。
在父元件的 <style scoped> 中給祖先類設定公開變數即可,不需要 :deep()。
<script setup lang="ts">
import { ref } from 'vue'
import { HuiFloatButton } from '@nscode/handy-ui'
const variableExplicit = ref(true)
const variableClicks = ref(0)
</script>
<template>
<div
class="float-button-variables-demo"
style="display:flex;flex-direction:column;gap:var(--hui-spacing-3);max-width:720px;--hui-float-button-width:64px;--hui-float-button-height:52px"
>
<button class="float-variable-toggle" @click="variableExplicit = !variableExplicit">
明確尺寸:{{ variableExplicit ? '48px/40px' : '未設定' }}
</button>
<span class="float-variable-result">點擊:{{ variableClicks }}</span>
<div
style="position:relative;height:200px;border:1px dashed var(--hui-border-color);margin-top:var(--hui-spacing-4)"
>
<HuiFloatButton
class="float-variable-inherited"
position="absolute"
:left="24"
:top="24"
icon="help"
aria-label="祖先尺寸按鈕"
:badge="3"
@click="variableClicks++"
/>
<HuiFloatButton
class="float-variable-explicit"
position="absolute"
:left="128"
:top="24"
:width="variableExplicit ? 48 : undefined"
:height="variableExplicit ? 40 : undefined"
icon="edit"
aria-label="明確尺寸按鈕"
style="--hui-float-button-width:60px;--hui-float-button-height:56px"
:badge="5"
@click="variableClicks++"
/>
<div
class="float-variable-nested"
style="--hui-float-button-width:36px;--hui-float-button-height:36px"
>
<HuiFloatButton
position="absolute"
:left="240"
:top="24"
icon="plus"
aria-label="局部尺寸按鈕"
@click="variableClicks++"
/>
</div>
</div>
</div>
</template>
選單狀態與公開方法
選單統一使用 visible、update:visible、open()、close()。傳入 visible 即受控,明確 undefined 表示關閉;未傳時自行保存狀態。受控請求仍等待父元件實際回填。上述名稱取代 showMenu、show-menu,不保留別名。
展開選單只有一個 Tab 停留點,上下鍵與 Home/End 可導覽可用子操作;輸入法組合和系統組合鍵保持原行為。關閉時於適當情況恢復主按鈕焦點。
<script setup lang="ts">
import { ref } from 'vue'
import { HuiButton, HuiFloatButton, HuiSpace } from '@nscode/handy-ui'
import type { FloatButtonExpose } from '@nscode/handy-ui'
const menu = ref<FloatButtonExpose>()
const visible = ref(false)
const selected = ref('尚無操作')
</script>
<template>
<HuiSpace direction="vertical" fill>
<HuiSpace
><HuiButton @click="menu?.open()">展開</HuiButton
><HuiButton @click="menu?.close()">收起</HuiButton></HuiSpace
>
<HuiFloatButton
ref="menu"
v-model:visible="visible"
position="relative"
icon="plus"
tooltip="更多操作"
>
<template #menu
><HuiFloatButton icon="help" tooltip="說明" @click="selected = '說明'" /><HuiFloatButton
icon="mail"
tooltip="意見回饋"
@click="selected = '意見回饋'"
/></template>
</HuiFloatButton>
<span>展開:{{ visible }};已選:{{ selected }}</span>
</HuiSpace>
</template>
Props
FloatButton
| 屬性 | 型別 | 預設值 | 說明 |
|---|---|---|---|
| icon | string | - | 圖示名(見《圖示》),和預設插槽二選一 |
| tooltip | string | - | 懸停或聚焦時的文字提示;只有圖示時也是按鈕的 aria-label |
| tooltip-placement | TooltipPlacement | 'left' | 文字提示的位置 |
| description | string | - | 圖示下面的小字,一般配合 shape="square" |
| type | 'default' | 'primary' | 'default' | 型別 |
| shape | 'circle' | 'square' | - | 形狀,不寫時是 circle。在群組中跟隨組(自行指定的不生效);在選單裡不寫時跟隨主按鈕 |
| position | 'fixed' | 'absolute' | 'relative' | 'fixed' | 定位方式。fixed 時 z-index 跟隨 HuiConfigProvider 的 zIndex(預設 2000)。在群組中、選單裡不生效 |
| left | number | string | - | 距離左邊,數值以 px。在群組中、選單裡不生效 |
| right | number | string | - | 距離右邊 |
| top | number | string | - | 距離上邊 |
| bottom | number | string | - | 距離下邊 |
| width | number | string | 40 | 寬度 |
| height | number | string | 40 | 高度(最小高度,內容放不下時變高) |
| badge | boolean | number | string | - | 右上角的角標:true 是小圓點,數字超過 99 顯示 99+;false、0 不顯示 |
| href | string | - | 連結地址,明確指定就渲染成 <a>;有選單時不生效 |
| target | string | - | 連結的 target,_blank 時自動加 rel="noopener noreferrer" |
| menu-trigger | 'click' | 'hover' | 'click' | 展開選單(menu 插槽)的觸發方式 |
| visible | boolean | undefined | 選單狀態;傳入即受控,明確undefined為關閉,未傳時自行保存 |
class、style 設定於根元素上(定位用);其他屬性(id、aria-label、data-* 等)和沒宣告的事件監聽放到真正的按鈕上。
FloatButtonGroup
| 屬性 | 型別 | 預設值 | 說明 |
|---|---|---|---|
| shape | 'circle' | 'square' | 'circle' | 群組中按鈕的形狀;square 時按鈕連成一整塊 |
| position | 'fixed' | 'absolute' | 'relative' | 'fixed' | 定位方式。fixed 時 z-index 跟隨 HuiConfigProvider 的 zIndex(預設 2000) |
| left | number | string | - | 距離左邊,數值以 px |
| right | number | string | - | 距離右邊 |
| top | number | string | - | 距離上邊 |
| bottom | number | string | - | 距離下邊 |
Events
FloatButton
| 事件 | 回呼參數 | 說明 |
|---|---|---|
| click | (event: MouseEvent) | 點擊主按鈕;選單裡的子按鈕觸發它們自己的 click |
| update:visible | (value: boolean) | 選單展開或收合,配合 v-model:visible |
FloatButtonGroup 沒有事件。
Slots
FloatButton
| 插槽 | 說明 |
|---|---|
| default | 圖示位置的內容,明確指定就不顯示 icon |
| description | 描述文字,優先於 description 屬性 |
| menu | 展開的子按鈕,放 HuiFloatButton;有這個插槽主按鈕才能展開 |
FloatButtonGroup
| 插槽 | 說明 |
|---|---|
| default | 群組中的 HuiFloatButton |
方法
FloatButton 通過 ref 暴露:
| 方法 | 參數 | 說明 |
|---|---|---|
| focus | - | 讓主按鈕獲得焦點 |
| blur | - | 讓主按鈕失去焦點 |
| open | - | 請求展開,沒有menu插槽時不操作 |
| close | - | 請求收起選單 |
FloatButtonGroup 沒有對外暴露的方法。
ref另提供唯讀visible,受控時反映父元件的實際回填值。
import type { FloatButtonExpose } from '@nscode/handy-ui'
interface FloatButtonExpose {
focus: () => void
blur: () => void
open: () => void
close: () => void
readonly visible: boolean
}
型別
import type {
FloatButtonProps,
FloatButtonEmits,
FloatButtonGroupProps,
FloatButtonShape,
FloatButtonType,
FloatButtonPosition,
FloatButtonMenuTrigger,
FloatButtonLength
} from '@nscode/handy-ui'
type FloatButtonShape = 'circle' | 'square'
type FloatButtonType = 'default' | 'primary'
type FloatButtonPosition = 'fixed' | 'absolute' | 'relative'
type FloatButtonMenuTrigger = 'click' | 'hover'
/** 數字和純數字的字串按 px,其他字串原樣使用 */
type FloatButtonLength = number | string
interface FloatButtonProps {
left?: FloatButtonLength
right?: FloatButtonLength
top?: FloatButtonLength
bottom?: FloatButtonLength
width?: FloatButtonLength
height?: FloatButtonLength
position?: FloatButtonPosition
shape?: FloatButtonShape
type?: FloatButtonType
icon?: HuiIconName
description?: string
tooltip?: string
tooltipPlacement?: TooltipPlacement
href?: string
target?: string
badge?: boolean | number | string
menuTrigger?: FloatButtonMenuTrigger
visible?: boolean
}
interface FloatButtonEmits {
click: [event: MouseEvent]
'update:visible': [value: boolean]
}
interface FloatButtonGroupProps {
left?: FloatButtonLength
right?: FloatButtonLength
top?: FloatButtonLength
bottom?: FloatButtonLength
position?: FloatButtonPosition
shape?: FloatButtonShape
}