可撤销提示条
Undo Toast
执行可逆操作后,状态提示提供撤销按钮。
适用场景
让归档、移除等操作容易撤销。 适合可以完整恢复先前状态的操作,撤销时也应还原条目原来的位置。
应用示例
用户在收件箱归档一封预订邮件,提示条显示「已归档」。点「撤销」后,这封邮件回到列表原来的位置。
相关设计技巧
删除可恢复的内容后,留一个撤销入口AI 提示词
执行【可逆操作】后显示可撤销提示条。撤销会恢复原值或原位置,按钮可用键盘操作,并播报移除和恢复的结果。
示例代码
保存为 HTML 文件后,用浏览器打开即可运行。代码与页面里的演示一致。
查看 HTML
<!doctype html>
<html lang="zh">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>可撤销提示条</title>
<style>
:root {
color-scheme: dark;
--demo-bg: #171629;
--demo-ink: #f8f5ff;
--demo-accent: #b9a6ff;
--demo-muted: #bfbbd3;
font-family: system-ui, sans-serif;
color: var(--demo-ink);
background: var(--demo-bg);
}
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; min-width: 0; }
button, input { font: inherit; }
.demo {
display: grid;
place-items: center;
align-content: center;
min-height: 100vh;
padding: 14px;
overflow: hidden;
background: radial-gradient(ellipse at 50% 24%, #28233f, var(--demo-bg) 78%);
}
.demo-button {
border: 1px solid #ffffff3d;
border-radius: 7px;
background: #ffffff12;
color: var(--demo-ink);
padding: 6px 11px;
font-size: 12px;
cursor: pointer;
}
:focus-visible {
outline: 2px solid var(--demo-accent);
outline-offset: 3px;
}
.example { width: min(100%, 228px); position: relative; display: grid; gap: 10px; }
.panel { background: #292240; border: 1px solid #675785; border-radius: 11px; padding: 10px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.label { margin: 0; font-size: 13px; font-weight: 650; }
.detail, .caption { margin: 0; color: #d7cbea; font-size: 11px; line-height: 1.35; }
.caption { text-align: center; }
.control { border: 1px solid #8874ae; background: #392e57; border-radius: 7px; padding: 5px 9px; min-height: 32px; color: #f6efff; cursor: pointer; font-size: 11px; font-weight: 650; }
.control:hover { background: #514174; }
.control.primary { color: #261b3f; background: #d1bfff; border-color: #e3d8ff; }
.control.primary:hover { background: #e3d8ff; }
.control:disabled { opacity: .55; cursor: default; }
.field { width: 100%; min-width: 0; padding: 6px 8px; border: 1px solid #875fa8; border-radius: 6px; color: #f6efff; background: #1e1732; font-size: 12px; }
.field::placeholder { color: #c2abd8; }
[hidden] { display: none !important; }
.undo { border-color: #b9daba; background: #2d413d; }
@media (prefers-reduced-motion: reduce) {
.example *, .example *::before, .example *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
</style>
</head>
<body>
<main class="demo">
<div class="example"><div class="panel row" data-item><p class="label">情绪板</p><button class="control" type="button" data-remove>移除</button></div><div class="panel row undo" data-undo-panel hidden><p class="detail" role="status">情绪板已移除。</p><button class="control primary" type="button" data-undo>撤销</button></div></div>
</main>
<script>
const item = document.querySelector('[data-item]');
const toast = document.querySelector('[data-undo-panel]');
const remove = document.querySelector('[data-remove]');
const undo = document.querySelector('[data-undo]');
remove.addEventListener('click', () => { item.hidden = true; toast.hidden = false; undo.focus(); });
undo.addEventListener('click', () => { item.hidden = false; toast.hidden = true; remove.focus(); });
</script>
</body>
</html>UI Skills 原创示例