button.html 946 B

123456789101112131415161718192021222324252627
  1. <button
  2. [type]="type()"
  3. [class]="classes()"
  4. [disabled]="disabled() || loading()"
  5. [attr.aria-busy]="loading() || null"
  6. [attr.aria-label]="ariaLabel() || (loading() ? '加载中' : null)"
  7. >
  8. <!--
  9. 🔴 [attr.aria-label] 的「加载中」兜底:加载态把内容整块换成 aria-hidden 的 spinner,
  10. 按钮就没有可访问名了(WAI-ARIA:aria-busy 不改变名字,disabled 也不会被读屏跳过)。
  11. 用属性块而非 `[attr.aria-busy]` 行内注释 —— 标签内的 HTML 注释会被当作属性解析,构建报 NG5002。
  12. -->
  13. @if (loading()) {
  14. <i class="fa-solid fa-spinner animate-spin" aria-hidden="true"></i>
  15. @if (loadingText()) {
  16. <span>{{ loadingText() }}</span>
  17. }
  18. } @else {
  19. @if (icon()) {
  20. <i [class]="icon()" aria-hidden="true"></i>
  21. }
  22. <ng-content />
  23. @if (iconRight()) {
  24. <i [class]="iconRight()" aria-hidden="true"></i>
  25. }
  26. }
  27. </button>