fix: 本地 patch MDUI 以解决 tabindex = 0 导致的一系列玄学问题

This commit is contained in:
CrescentLeaf
2025-10-04 11:07:03 +08:00
parent af694f6f6c
commit 6e164cbdfb
480 changed files with 94389 additions and 0 deletions

View File

@@ -0,0 +1,72 @@
import { ButtonBase } from '../button/button-base.js';
import '../icon.js';
import type { Ripple } from '../ripple/index.js';
import type { CSSResultGroup, PropertyValues, TemplateResult } from 'lit';
/**
* @summary 图标按钮组件
*
* ```html
* <mdui-button-icon icon="search"></mdui-button-icon>
* ```
*
* @event focus - 获得焦点时触发
* @event blur - 失去焦点时触发
* @event change - 选中状态变更时触发
* @event invalid - 表单字段验证未通过时触发
*
* @slot - 图标组件
* @slot selected-icon 选中状态显示的图标元素
*
* @csspart button - 内部的 `<button>` 或 `<a>` 元素
* @csspart icon - 未选中状态的图标
* @csspart selected-icon 选中状态的图标
* @csspart loading - 加载中状态的 `<mdui-circular-progress>` 元素
*
* @cssprop --shape-corner - 组件的圆角大小。可以指定一个具体的像素值;但更推荐引用[设计令牌](/docs/2/styles/design-tokens#shape-corner)
*/
export declare class ButtonIcon extends ButtonBase<ButtonIconEventMap> {
static styles: CSSResultGroup;
/**
* 图标按钮的形状。可选值包括:
*
* * `standard`:适用于最低优先级的操作
* * `filled`:视觉效果强烈,适用于高优先级的操作
* * `tonal`:视觉效果介于 `filled` 和 `outlined` 之间,适用于中高优先级的操作
* * `outlined`:适用于中等优先级的操作
*/
variant: /*适用于最低优先级的操作*/ 'standard' | /*视觉效果强烈,适用于高优先级的操作*/ 'filled' | /*视觉效果介于 `filled` 和 `outlined` 之间,适用于中高优先级的操作*/ 'tonal' | /*适用于中等优先级的操作*/ 'outlined';
/**
* Material Icons 图标名。也可以通过 default slot 设置
*/
icon?: string;
/**
* 选中状态的 Material Icons 图标名。也可以通过 `slot="selected-icon"` 设置
*/
selectedIcon?: string;
/**
* 是否可选中
*/
selectable: boolean;
/**
* 是否已被选中
*/
selected: boolean;
private readonly rippleRef;
private readonly hasSlotController;
protected get rippleElement(): Ripple;
private onSelectedChange;
protected firstUpdated(changedProperties: PropertyValues): void;
protected render(): TemplateResult;
private renderIcon;
}
export interface ButtonIconEventMap {
focus: FocusEvent;
blur: FocusEvent;
change: CustomEvent<void>;
invalid: CustomEvent<void>;
}
declare global {
interface HTMLElementTagNameMap {
'mdui-button-icon': ButtonIcon;
}
}

View File

@@ -0,0 +1,129 @@
import { __decorate } from "tslib";
import { html } from 'lit';
import { customElement, property } from 'lit/decorators.js';
import { createRef, ref } from 'lit/directives/ref.js';
import { HasSlotController } from '@mdui/shared/controllers/has-slot.js';
import { watch } from '@mdui/shared/decorators/watch.js';
import { booleanConverter } from '@mdui/shared/helpers/decorator.js';
import { nothingTemplate } from '@mdui/shared/helpers/template.js';
import { ButtonBase } from '../button/button-base.js';
import '../icon.js';
import { style } from './style.js';
/**
* @summary 图标按钮组件
*
* ```html
* <mdui-button-icon icon="search"></mdui-button-icon>
* ```
*
* @event focus - 获得焦点时触发
* @event blur - 失去焦点时触发
* @event change - 选中状态变更时触发
* @event invalid - 表单字段验证未通过时触发
*
* @slot - 图标组件
* @slot selected-icon 选中状态显示的图标元素
*
* @csspart button - 内部的 `<button>` 或 `<a>` 元素
* @csspart icon - 未选中状态的图标
* @csspart selected-icon 选中状态的图标
* @csspart loading - 加载中状态的 `<mdui-circular-progress>` 元素
*
* @cssprop --shape-corner - 组件的圆角大小。可以指定一个具体的像素值;但更推荐引用[设计令牌](/docs/2/styles/design-tokens#shape-corner)
*/
let ButtonIcon = class ButtonIcon extends ButtonBase {
constructor() {
super(...arguments);
/**
* 图标按钮的形状。可选值包括:
*
* * `standard`:适用于最低优先级的操作
* * `filled`:视觉效果强烈,适用于高优先级的操作
* * `tonal`:视觉效果介于 `filled` 和 `outlined` 之间,适用于中高优先级的操作
* * `outlined`:适用于中等优先级的操作
*/
this.variant = 'standard';
/**
* 是否可选中
*/
this.selectable = false;
/**
* 是否已被选中
*/
this.selected = false;
this.rippleRef = createRef();
this.hasSlotController = new HasSlotController(this, '[default]', 'selected-icon');
}
get rippleElement() {
return this.rippleRef.value;
}
onSelectedChange() {
this.emit('change');
}
firstUpdated(changedProperties) {
super.firstUpdated(changedProperties);
this.addEventListener('click', () => {
if (!this.selectable || this.disabled) {
return;
}
this.selected = !this.selected;
});
}
render() {
return html `<mdui-ripple ${ref(this.rippleRef)} .noRipple="${this.noRipple}"></mdui-ripple>${this.isButton()
? this.renderButton({
className: 'button',
part: 'button',
content: this.renderIcon(),
})
: this.disabled || this.loading
? html `<span part="button" class="button _a">${this.renderIcon()}</span>`
: this.renderAnchor({
className: 'button',
part: 'button',
content: this.renderIcon(),
})} ${this.renderLoading()}`;
}
renderIcon() {
const icon = () => this.hasSlotController.test('[default]')
? html `<slot></slot>`
: this.icon
? html `<mdui-icon part="icon" class="icon" name="${this.icon}"></mdui-icon>`
: nothingTemplate;
const selectedIcon = () => this.hasSlotController.test('selected-icon') || this.selectedIcon
? html `<slot name="selected-icon" part="selected-icon" class="selected-icon"><mdui-icon name="${this.selectedIcon}"></mdui-icon></slot>`
: icon();
return this.selected ? selectedIcon() : icon();
}
};
ButtonIcon.styles = [ButtonBase.styles, style];
__decorate([
property({ reflect: true })
], ButtonIcon.prototype, "variant", void 0);
__decorate([
property({ reflect: true })
], ButtonIcon.prototype, "icon", void 0);
__decorate([
property({ reflect: true, attribute: 'selected-icon' })
], ButtonIcon.prototype, "selectedIcon", void 0);
__decorate([
property({
type: Boolean,
reflect: true,
converter: booleanConverter,
})
], ButtonIcon.prototype, "selectable", void 0);
__decorate([
property({
type: Boolean,
reflect: true,
converter: booleanConverter,
})
], ButtonIcon.prototype, "selected", void 0);
__decorate([
watch('selected', true)
], ButtonIcon.prototype, "onSelectedChange", null);
ButtonIcon = __decorate([
customElement('mdui-button-icon')
], ButtonIcon);
export { ButtonIcon };

View File

@@ -0,0 +1 @@
export declare const style: import("lit").CSSResult;

View File

@@ -0,0 +1,4 @@
import { css } from 'lit';
export const style = css `:host{--shape-corner:var(--mdui-shape-corner-full);position:relative;display:inline-block;flex-shrink:0;overflow:hidden;text-align:center;border-radius:var(--shape-corner);cursor:pointer;-webkit-tap-highlight-color:transparent;font-size:1.5rem;width:2.5rem;height:2.5rem}:host([variant=standard]){color:rgb(var(--mdui-color-on-surface-variant));--mdui-comp-ripple-state-layer-color:var(--mdui-color-on-surface-variant)}:host([variant=filled]){color:rgb(var(--mdui-color-primary));background-color:rgb(var(--mdui-color-surface-container-highest));--mdui-comp-ripple-state-layer-color:var(--mdui-color-primary)}:host([variant=tonal]){color:rgb(var(--mdui-color-on-surface-variant));background-color:rgb(var(--mdui-color-surface-container-highest));--mdui-comp-ripple-state-layer-color:var(--mdui-color-on-surface-variant)}:host([variant=outlined]){border:.0625rem solid rgb(var(--mdui-color-outline));color:rgb(var(--mdui-color-on-surface-variant));--mdui-comp-ripple-state-layer-color:var(--mdui-color-on-surface-variant)}:host([variant=outlined][pressed]){color:rgb(var(--mdui-color-on-surface));--mdui-comp-ripple-state-layer-color:var(--mdui-color-on-surface)}:host([variant=standard][selected]:not([selected=false i])){color:rgb(var(--mdui-color-primary));--mdui-comp-ripple-state-layer-color:var(--mdui-color-primary)}:host([variant=filled]:not([selectable])),:host([variant=filled][selectable=false i]),:host([variant=filled][selected]:not([selected=false i])){color:rgb(var(--mdui-color-on-primary));background-color:rgb(var(--mdui-color-primary));--mdui-comp-ripple-state-layer-color:var(--mdui-color-on-primary)}:host([variant=tonal]:not([selectable])),:host([variant=tonal][selectable=false i]),:host([variant=tonal][selected]:not([selected=false i])){color:rgb(var(--mdui-color-on-secondary-container));background-color:rgb(var(--mdui-color-secondary-container));--mdui-comp-ripple-state-layer-color:var(
--mdui-color-on-secondary-container
)}:host([variant=outlined][selected]:not([selected=false i])){border:none;color:rgb(var(--mdui-color-inverse-on-surface));background-color:rgb(var(--mdui-color-inverse-surface));--mdui-comp-ripple-state-layer-color:var(--mdui-color-inverse-on-surface)}:host([variant=filled][disabled]:not([disabled=false i])),:host([variant=outlined][disabled]:not([disabled=false i])),:host([variant=tonal][disabled]:not([disabled=false i])){background-color:rgba(var(--mdui-color-on-surface),.12);border-color:rgba(var(--mdui-color-on-surface),.12)}:host([disabled]:not([disabled=false i])),:host([loading]:not([loading=false i])){cursor:default;pointer-events:none}:host([disabled]:not([disabled=false i])){color:rgba(var(--mdui-color-on-surface),.38)!important}.button{float:left;width:100%}:host([loading]:not([loading=false i])) .button,:host([loading]:not([loading=false i])) mdui-ripple{opacity:0}.icon,.selected-icon mdui-icon,::slotted(*){font-size:inherit}mdui-circular-progress{display:flex;position:absolute;top:calc(50% - 1.5rem / 2);left:calc(50% - 1.5rem / 2);width:1.5rem;height:1.5rem}:host([variant=filled]:not([disabled])) mdui-circular-progress,:host([variant=filled][disabled=false i]) mdui-circular-progress{stroke:rgb(var(--mdui-color-on-primary))}:host([disabled]:not([disabled=false i])) mdui-circular-progress{stroke:rgba(var(--mdui-color-on-surface),38%)}`;