mdui 2.0.2 → 2.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/avatar/index.d.ts +17 -15
- package/components/avatar/index.js +7 -6
- package/components/badge/index.d.ts +11 -8
- package/components/badge/index.js +9 -7
- package/components/bottom-app-bar/index.d.ts +11 -4
- package/components/bottom-app-bar/index.js +8 -9
- package/components/button/button-base-style.js +1 -1
- package/components/button/button-base.d.ts +46 -47
- package/components/button/button-base.js +27 -25
- package/components/button/index.d.ts +19 -14
- package/components/button/index.js +12 -12
- package/components/button-icon/index.d.ts +15 -9
- package/components/button-icon/index.js +8 -9
- package/components/card/index.d.ts +15 -11
- package/components/card/index.js +10 -9
- package/components/checkbox/index.d.ts +30 -23
- package/components/checkbox/index.js +25 -25
- package/components/chip/index.d.ts +27 -20
- package/components/chip/index.js +19 -20
- package/components/circular-progress/index.d.ts +6 -4
- package/components/circular-progress/index.js +4 -3
- package/components/collapse/collapse-item.d.ts +17 -6
- package/components/collapse/collapse-item.js +7 -7
- package/components/collapse/collapse.d.ts +16 -11
- package/components/collapse/collapse.js +10 -10
- package/components/dialog/index.d.ts +22 -15
- package/components/dialog/index.js +23 -27
- package/components/divider/index.d.ts +7 -5
- package/components/divider/index.js +6 -5
- package/components/dropdown/index.d.ts +44 -37
- package/components/dropdown/index.js +50 -48
- package/components/fab/index.d.ts +12 -7
- package/components/fab/index.js +6 -6
- package/components/icon/index.d.ts +4 -2
- package/components/icon/index.js +3 -2
- package/components/layout/layout-item-base.d.ts +3 -2
- package/components/layout/layout-item-base.js +2 -2
- package/components/layout/layout-item.d.ts +11 -10
- package/components/layout/layout-item.js +6 -6
- package/components/layout/layout-main.d.ts +6 -4
- package/components/layout/layout-main.js +5 -4
- package/components/layout/layout.d.ts +6 -4
- package/components/layout/layout.js +5 -4
- package/components/linear-progress/index.d.ts +8 -6
- package/components/linear-progress/index.js +6 -5
- package/components/list/list-item-style.js +1 -1
- package/components/list/list-item.d.ts +24 -20
- package/components/list/list-item.js +10 -9
- package/components/list/list-subheader.d.ts +6 -4
- package/components/list/list-subheader.js +5 -4
- package/components/list/list.d.ts +5 -3
- package/components/list/list.js +4 -3
- package/components/menu/menu-item.d.ts +15 -7
- package/components/menu/menu-item.js +11 -15
- package/components/menu/menu.d.ts +20 -20
- package/components/menu/menu.js +13 -13
- package/components/navigation-bar/navigation-bar-item.d.ts +12 -8
- package/components/navigation-bar/navigation-bar-item.js +7 -6
- package/components/navigation-bar/navigation-bar.d.ts +17 -9
- package/components/navigation-bar/navigation-bar.js +15 -13
- package/components/navigation-drawer/index.d.ts +27 -21
- package/components/navigation-drawer/index.js +51 -38
- package/components/navigation-drawer/style.js +1 -1
- package/components/navigation-rail/navigation-rail-item.d.ts +13 -9
- package/components/navigation-rail/navigation-rail-item.js +7 -6
- package/components/navigation-rail/navigation-rail.d.ts +14 -12
- package/components/navigation-rail/navigation-rail.js +13 -12
- package/components/radio/radio-group.d.ts +20 -15
- package/components/radio/radio-group.js +21 -24
- package/components/radio/radio.d.ts +11 -6
- package/components/radio/radio.js +7 -7
- package/components/range-slider/index.d.ts +13 -8
- package/components/range-slider/index.js +10 -7
- package/components/ripple/index.d.ts +4 -2
- package/components/ripple/index.js +3 -2
- package/components/ripple/ripple-mixin.d.ts +1 -1
- package/components/ripple/ripple-mixin.js +0 -1
- package/components/segmented-button/segmented-button-group-style.js +1 -1
- package/components/segmented-button/segmented-button-group.d.ts +23 -22
- package/components/segmented-button/segmented-button-group.js +20 -23
- package/components/segmented-button/segmented-button.d.ts +9 -4
- package/components/segmented-button/segmented-button.js +3 -3
- package/components/select/index.d.ts +42 -35
- package/components/select/index.js +24 -25
- package/components/slider/index.d.ts +9 -2
- package/components/slider/index.js +5 -10
- package/components/slider/slider-base.d.ts +22 -18
- package/components/slider/slider-base.js +40 -21
- package/components/snackbar/index.d.ts +30 -23
- package/components/snackbar/index.js +25 -25
- package/components/switch/index.d.ts +24 -17
- package/components/switch/index.js +18 -18
- package/components/tabs/tab-panel.d.ts +7 -5
- package/components/tabs/tab-panel.js +5 -4
- package/components/tabs/tab.d.ts +13 -9
- package/components/tabs/tab.js +8 -7
- package/components/tabs/tabs.d.ts +24 -21
- package/components/tabs/tabs.js +24 -21
- package/components/text-field/index.d.ts +62 -54
- package/components/text-field/index.js +37 -37
- package/components/tooltip/index.d.ts +40 -33
- package/components/tooltip/index.js +45 -43
- package/components/top-app-bar/top-app-bar-title.d.ts +8 -6
- package/components/top-app-bar/top-app-bar-title.js +7 -6
- package/components/top-app-bar/top-app-bar.d.ts +12 -6
- package/components/top-app-bar/top-app-bar.js +9 -10
- package/css-data.en.json +2826 -0
- package/css-data.zh-cn.json +374 -367
- package/custom-elements.json +3844 -3824
- package/html-data.en.json +6551 -0
- package/html-data.zh-cn.json +1621 -1636
- package/jsx.en.d.ts +3303 -0
- package/jsx.zh-cn.d.ts +3351 -0
- package/mdui.esm.js +9 -9
- package/mdui.global.js +9 -9
- package/package.json +7 -5
- package/web-types.en.json +11718 -0
- package/web-types.zh-cn.json +3613 -3623
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { __decorate } from "tslib";
|
|
2
|
-
import { html
|
|
2
|
+
import { html } from 'lit';
|
|
3
3
|
import { customElement, property, state } from 'lit/decorators.js';
|
|
4
4
|
import { ifDefined } from 'lit/directives/if-defined.js';
|
|
5
5
|
import { map } from 'lit/directives/map.js';
|
|
@@ -9,17 +9,17 @@ import { $ } from '@mdui/jq/$.js';
|
|
|
9
9
|
import '@mdui/jq/methods/find.js';
|
|
10
10
|
import '@mdui/jq/methods/get.js';
|
|
11
11
|
import { isString } from '@mdui/jq/shared/helper.js';
|
|
12
|
+
import { MduiElement } from '@mdui/shared/base/mdui-element.js';
|
|
12
13
|
import { DefinedController } from '@mdui/shared/controllers/defined.js';
|
|
13
14
|
import { FormController, formResets } from '@mdui/shared/controllers/form.js';
|
|
14
15
|
import { defaultValue } from '@mdui/shared/decorators/default-value.js';
|
|
15
16
|
import { watch } from '@mdui/shared/decorators/watch.js';
|
|
16
17
|
import { arraysEqualIgnoreOrder } from '@mdui/shared/helpers/array.js';
|
|
17
18
|
import { booleanConverter } from '@mdui/shared/helpers/decorator.js';
|
|
18
|
-
import { emit } from '@mdui/shared/helpers/event.js';
|
|
19
19
|
import { componentStyle } from '@mdui/shared/lit-styles/component-style.js';
|
|
20
20
|
import { segmentedButtonGroupStyle } from './segmented-button-group-style.js';
|
|
21
21
|
/**
|
|
22
|
-
* @summary
|
|
22
|
+
* @summary 分段按钮组件。需配合 `<mdui-segmented-button>` 组件使用
|
|
23
23
|
*
|
|
24
24
|
* ```html
|
|
25
25
|
* <mdui-segmented-button-group>
|
|
@@ -34,9 +34,9 @@ import { segmentedButtonGroupStyle } from './segmented-button-group-style.js';
|
|
|
34
34
|
*
|
|
35
35
|
* @slot - `<mdui-segmented-button>` 组件
|
|
36
36
|
*
|
|
37
|
-
* @cssprop --shape-corner -
|
|
37
|
+
* @cssprop --shape-corner - 组件的圆角大小。可以指定一个具体的像素值;但更推荐引用[设计令牌](/docs/2/styles/design-tokens#shape-corner)
|
|
38
38
|
*/
|
|
39
|
-
let SegmentedButtonGroup = class SegmentedButtonGroup extends
|
|
39
|
+
let SegmentedButtonGroup = class SegmentedButtonGroup extends MduiElement {
|
|
40
40
|
constructor() {
|
|
41
41
|
super(...arguments);
|
|
42
42
|
/**
|
|
@@ -56,12 +56,9 @@ let SegmentedButtonGroup = class SegmentedButtonGroup extends LitElement {
|
|
|
56
56
|
*/
|
|
57
57
|
this.name = '';
|
|
58
58
|
/**
|
|
59
|
-
* 当前选中的 `<mdui-segmented-button>`
|
|
59
|
+
* 当前选中的 `<mdui-segmented-button>` 的值。
|
|
60
60
|
*
|
|
61
|
-
* Note
|
|
62
|
-
* 该属性的 HTML 属性始终为字符串,且仅在 `selects="single"` 时可以通过 HTML 属性设置初始值
|
|
63
|
-
* 该属性的 JavaScript 属性值在 `selects="single"` 时为字符串,在 `selects="multiple"` 时为字符串数组。
|
|
64
|
-
* 所以,在 `selects="multiple"` 时,如果要修改该值,只能通过修改 JavaScript 属性值实现。
|
|
61
|
+
* **Note**:该属性的 HTML 属性始终为字符串,且仅在 `selects="single"` 时可以通过 HTML 属性设置初始值。该属性的 JavaScript 属性值在 `selects="single"` 时为字符串,在 `selects="multiple"` 时为字符串数组。所以,在 `selects="multiple"` 时,如果要修改该值,只能通过修改 JavaScript 属性值实现。
|
|
65
62
|
*/
|
|
66
63
|
this.value = '';
|
|
67
64
|
/**
|
|
@@ -83,13 +80,13 @@ let SegmentedButtonGroup = class SegmentedButtonGroup extends LitElement {
|
|
|
83
80
|
});
|
|
84
81
|
}
|
|
85
82
|
/**
|
|
86
|
-
*
|
|
83
|
+
* 表单验证状态对象,具体参见 [`ValidityState`](https://developer.mozilla.org/zh-CN/docs/Web/API/ValidityState)
|
|
87
84
|
*/
|
|
88
85
|
get validity() {
|
|
89
86
|
return this.inputRef.value.validity;
|
|
90
87
|
}
|
|
91
88
|
/**
|
|
92
|
-
*
|
|
89
|
+
* 如果表单验证未通过,此属性将包含提示信息。如果验证通过,此属性将为空字符串
|
|
93
90
|
*/
|
|
94
91
|
get validationMessage() {
|
|
95
92
|
return this.inputRef.value.validationMessage;
|
|
@@ -138,7 +135,7 @@ let SegmentedButtonGroup = class SegmentedButtonGroup extends LitElement {
|
|
|
138
135
|
const value = this.isMultiple ? values : values[0] || '';
|
|
139
136
|
this.setValue(value);
|
|
140
137
|
if (!this.isInitial) {
|
|
141
|
-
emit(
|
|
138
|
+
this.emit('change');
|
|
142
139
|
}
|
|
143
140
|
}
|
|
144
141
|
async onValueChange() {
|
|
@@ -195,12 +192,12 @@ let SegmentedButtonGroup = class SegmentedButtonGroup extends LitElement {
|
|
|
195
192
|
this.defaultValue = this.selects === 'multiple' ? [] : '';
|
|
196
193
|
}
|
|
197
194
|
/**
|
|
198
|
-
*
|
|
195
|
+
* 检查表单字段是否通过验证。如果未通过,返回 `false` 并触发 `invalid` 事件;如果通过,返回 `true`
|
|
199
196
|
*/
|
|
200
197
|
checkValidity() {
|
|
201
198
|
const valid = this.inputRef.value.checkValidity();
|
|
202
199
|
if (!valid) {
|
|
203
|
-
emit(
|
|
200
|
+
this.emit('invalid', {
|
|
204
201
|
bubbles: false,
|
|
205
202
|
cancelable: true,
|
|
206
203
|
composed: false,
|
|
@@ -209,20 +206,20 @@ let SegmentedButtonGroup = class SegmentedButtonGroup extends LitElement {
|
|
|
209
206
|
return valid;
|
|
210
207
|
}
|
|
211
208
|
/**
|
|
212
|
-
*
|
|
209
|
+
* 检查表单字段是否通过验证。如果未通过,返回 `false` 并触发 `invalid` 事件;如果通过,返回 `true`。
|
|
213
210
|
*
|
|
214
|
-
*
|
|
211
|
+
* 如果验证未通过,还会在组件上显示验证失败的提示。
|
|
215
212
|
*/
|
|
216
213
|
reportValidity() {
|
|
217
214
|
this.invalid = !this.inputRef.value.reportValidity();
|
|
218
215
|
if (this.invalid) {
|
|
219
|
-
const
|
|
216
|
+
const eventProceeded = this.emit('invalid', {
|
|
220
217
|
bubbles: false,
|
|
221
218
|
cancelable: true,
|
|
222
219
|
composed: false,
|
|
223
220
|
});
|
|
224
|
-
|
|
225
|
-
|
|
221
|
+
if (!eventProceeded) {
|
|
222
|
+
// 调用了 preventDefault() 时,隐藏默认的表单错误提示
|
|
226
223
|
this.inputRef.value.blur();
|
|
227
224
|
this.inputRef.value.focus();
|
|
228
225
|
}
|
|
@@ -230,9 +227,9 @@ let SegmentedButtonGroup = class SegmentedButtonGroup extends LitElement {
|
|
|
230
227
|
return !this.invalid;
|
|
231
228
|
}
|
|
232
229
|
/**
|
|
233
|
-
*
|
|
230
|
+
* 设置自定义的错误提示文本。只要这个文本不为空,就表示字段未通过验证
|
|
234
231
|
*
|
|
235
|
-
* @param message
|
|
232
|
+
* @param message 自定义的错误提示文本
|
|
236
233
|
*/
|
|
237
234
|
setCustomValidity(message) {
|
|
238
235
|
this.inputRef.value.setCustomValidity(message);
|
|
@@ -273,7 +270,7 @@ let SegmentedButtonGroup = class SegmentedButtonGroup extends LitElement {
|
|
|
273
270
|
await this.definedController.whenDefined();
|
|
274
271
|
const target = event.target;
|
|
275
272
|
const item = target.closest('mdui-segmented-button');
|
|
276
|
-
if (item.disabled) {
|
|
273
|
+
if (!item || item.disabled) {
|
|
277
274
|
return;
|
|
278
275
|
}
|
|
279
276
|
if (this.isSelectable && item.value) {
|
|
@@ -4,7 +4,7 @@ import '../icon.js';
|
|
|
4
4
|
import type { Ripple } from '../ripple/index.js';
|
|
5
5
|
import type { CSSResultGroup, TemplateResult } from 'lit';
|
|
6
6
|
/**
|
|
7
|
-
* @summary
|
|
7
|
+
* @summary 分段按钮项组件。需配合 `<mdui-segmented-button-group>` 组件使用
|
|
8
8
|
*
|
|
9
9
|
* ```html
|
|
10
10
|
* <mdui-segmented-button-group>
|
|
@@ -18,19 +18,19 @@ import type { CSSResultGroup, TemplateResult } from 'lit';
|
|
|
18
18
|
* @event blur - 失去焦点时触发
|
|
19
19
|
* @event invalid - 表单字段验证未通过时触发
|
|
20
20
|
*
|
|
21
|
-
* @slot -
|
|
21
|
+
* @slot - 分段按钮项的文本内容
|
|
22
22
|
* @slot icon - 分段按钮项的左侧图标
|
|
23
23
|
* @slot selected-icon - 选中状态的左侧图标
|
|
24
24
|
* @slot end-icon - 分段按钮项的右侧图标
|
|
25
25
|
*
|
|
26
|
-
* @csspart button - 内部的 button 或 a 元素
|
|
26
|
+
* @csspart button - 内部的 `<button>` 或 `<a>` 元素
|
|
27
27
|
* @csspart icon - 左侧的图标
|
|
28
28
|
* @csspart selected-icon - 选中状态的左侧图标
|
|
29
29
|
* @csspart end-icon - 右侧的图标
|
|
30
30
|
* @csspart label - 文本内容
|
|
31
31
|
* @csspart loading - 加载中状态的 `<mdui-circular-progress>` 元素
|
|
32
32
|
*/
|
|
33
|
-
export declare class SegmentedButton extends ButtonBase {
|
|
33
|
+
export declare class SegmentedButton extends ButtonBase<SegmentedButtonEventMap> {
|
|
34
34
|
static styles: CSSResultGroup;
|
|
35
35
|
/**
|
|
36
36
|
* 左侧的 Material Icons 图标名。也可以通过 `slot="icon"` 设置
|
|
@@ -66,6 +66,11 @@ export declare class SegmentedButton extends ButtonBase {
|
|
|
66
66
|
private renderEndIcon;
|
|
67
67
|
private renderInner;
|
|
68
68
|
}
|
|
69
|
+
export interface SegmentedButtonEventMap {
|
|
70
|
+
focus: FocusEvent;
|
|
71
|
+
blur: FocusEvent;
|
|
72
|
+
invalid: CustomEvent<void>;
|
|
73
|
+
}
|
|
69
74
|
declare global {
|
|
70
75
|
interface HTMLElementTagNameMap {
|
|
71
76
|
'mdui-segmented-button': SegmentedButton;
|
|
@@ -12,7 +12,7 @@ import { ButtonBase } from '../button/button-base.js';
|
|
|
12
12
|
import '../icon.js';
|
|
13
13
|
import { segmentedButtonStyle } from './segmented-button-style.js';
|
|
14
14
|
/**
|
|
15
|
-
* @summary
|
|
15
|
+
* @summary 分段按钮项组件。需配合 `<mdui-segmented-button-group>` 组件使用
|
|
16
16
|
*
|
|
17
17
|
* ```html
|
|
18
18
|
* <mdui-segmented-button-group>
|
|
@@ -26,12 +26,12 @@ import { segmentedButtonStyle } from './segmented-button-style.js';
|
|
|
26
26
|
* @event blur - 失去焦点时触发
|
|
27
27
|
* @event invalid - 表单字段验证未通过时触发
|
|
28
28
|
*
|
|
29
|
-
* @slot -
|
|
29
|
+
* @slot - 分段按钮项的文本内容
|
|
30
30
|
* @slot icon - 分段按钮项的左侧图标
|
|
31
31
|
* @slot selected-icon - 选中状态的左侧图标
|
|
32
32
|
* @slot end-icon - 分段按钮项的右侧图标
|
|
33
33
|
*
|
|
34
|
-
* @csspart button - 内部的 button 或 a 元素
|
|
34
|
+
* @csspart button - 内部的 `<button>` 或 `<a>` 元素
|
|
35
35
|
* @csspart icon - 左侧的图标
|
|
36
36
|
* @csspart selected-icon - 选中状态的左侧图标
|
|
37
37
|
* @csspart end-icon - 右侧的图标
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PropertyValues } from 'lit';
|
|
2
|
+
import { MduiElement } from '@mdui/shared/base/mdui-element.js';
|
|
2
3
|
import '../chip.js';
|
|
3
4
|
import '../dropdown.js';
|
|
4
5
|
import '../menu.js';
|
|
5
6
|
import '../text-field.js';
|
|
6
7
|
import type { FormControl } from '@mdui/jq/shared/form.js';
|
|
7
8
|
import type { CSSResultGroup, TemplateResult } from 'lit';
|
|
8
|
-
declare const Select_base: import("@open-wc/dedupe-mixin").Constructor<import("@mdui/shared/mixins/focusable.js").FocusableMixinInterface> & typeof
|
|
9
|
+
declare const Select_base: import("@open-wc/dedupe-mixin").Constructor<import("@mdui/shared/mixins/focusable.js").FocusableMixinInterface> & typeof MduiElement;
|
|
9
10
|
/**
|
|
10
|
-
* @summary
|
|
11
|
+
* @summary 选择框组件。需配合 `<mdui-menu-item>` 组件使用
|
|
11
12
|
*
|
|
12
13
|
* ```html
|
|
13
14
|
* <mdui-select>
|
|
@@ -20,7 +21,7 @@ declare const Select_base: import("@open-wc/dedupe-mixin").Constructor<import("@
|
|
|
20
21
|
* @event blur - 失去焦点时触发
|
|
21
22
|
* @event change - 选中的值变更时触发
|
|
22
23
|
* @event invalid - 表单字段验证未通过时触发
|
|
23
|
-
* @event clear - 在点击由 `clearable` 属性生成的清空按钮时触发。可以通过调用 `event.preventDefault()`
|
|
24
|
+
* @event clear - 在点击由 `clearable` 属性生成的清空按钮时触发。可以通过调用 `event.preventDefault()` 阻止清空选择框
|
|
24
25
|
*
|
|
25
26
|
* @slot - `<mdui-menu-item>` 元素
|
|
26
27
|
* @slot icon - 左侧图标
|
|
@@ -35,28 +36,27 @@ declare const Select_base: import("@open-wc/dedupe-mixin").Constructor<import("@
|
|
|
35
36
|
* @csspart text-field - 文本框,即 [`<mdui-text-field>`](/docs/2/components/text-field) 元素
|
|
36
37
|
* @csspart menu - 下拉菜单,即 [`<mdui-menu>`](/docs/2/components/menu) 元素
|
|
37
38
|
*/
|
|
38
|
-
export declare class Select extends Select_base implements FormControl {
|
|
39
|
+
export declare class Select extends Select_base<SelectEventMap> implements FormControl {
|
|
39
40
|
static styles: CSSResultGroup;
|
|
40
41
|
/**
|
|
41
|
-
*
|
|
42
|
+
* 选择框的样式。可选值包括:
|
|
42
43
|
*
|
|
43
|
-
* * `filled
|
|
44
|
-
* * `outlined
|
|
44
|
+
* * `filled`:带背景色的选择框,视觉效果较强
|
|
45
|
+
* * `outlined`:带边框的选择框,视觉效果较弱
|
|
45
46
|
*/
|
|
46
|
-
variant:
|
|
47
|
+
variant: /*带背景色的选择框,视觉效果较强*/ 'filled' | /*带边框的选择框,视觉效果较弱*/ 'outlined';
|
|
47
48
|
/**
|
|
48
49
|
* 是否支持多选
|
|
49
50
|
*/
|
|
50
51
|
multiple: boolean;
|
|
51
52
|
/**
|
|
52
|
-
*
|
|
53
|
+
* 选择框的名称,将与表单数据一起提交
|
|
53
54
|
*/
|
|
54
55
|
name: string;
|
|
55
56
|
/**
|
|
56
|
-
*
|
|
57
|
+
* 选择框的值,将与表单数据一起提交。
|
|
57
58
|
*
|
|
58
|
-
*
|
|
59
|
-
* HTML 属性只能设置字符串值;如果需要设置数组值,请通过 JavaScript 设置
|
|
59
|
+
* 如果未指定 `multiple` 属性,该值为字符串;如果指定了 `multiple` 属性,该值为字符串数组。HTML 属性只能设置字符串值;如果需要设置数组值,请通过 JavaScript 属性设置。
|
|
60
60
|
*/
|
|
61
61
|
value: string | string[];
|
|
62
62
|
/**
|
|
@@ -68,61 +68,61 @@ export declare class Select extends Select_base implements FormControl {
|
|
|
68
68
|
*/
|
|
69
69
|
label?: string;
|
|
70
70
|
/**
|
|
71
|
-
*
|
|
71
|
+
* 占位符文本
|
|
72
72
|
*/
|
|
73
73
|
placeholder?: string;
|
|
74
74
|
/**
|
|
75
|
-
*
|
|
75
|
+
* 选择框底部的帮助文本。也可以通过 `slot="helper"` 设置
|
|
76
76
|
*/
|
|
77
77
|
helper?: string;
|
|
78
78
|
/**
|
|
79
|
-
*
|
|
79
|
+
* 是否可以清空选择框
|
|
80
80
|
*/
|
|
81
81
|
clearable: boolean;
|
|
82
82
|
/**
|
|
83
|
-
*
|
|
83
|
+
* 当选择框可清空时,显示在选择框右侧的清空按钮的 Material Icons 图标名。也可以通过 `slot="clear-icon"` 设置
|
|
84
84
|
*/
|
|
85
85
|
clearIcon?: string;
|
|
86
86
|
/**
|
|
87
|
-
*
|
|
87
|
+
* 选择框的位置。可选值包括:
|
|
88
88
|
*
|
|
89
|
-
* * `auto
|
|
89
|
+
* * `auto`:自动判断位置
|
|
90
90
|
* * `bottom`:位于下方
|
|
91
91
|
* * `top`:位于上方
|
|
92
92
|
*/
|
|
93
|
-
placement:
|
|
93
|
+
placement: /*自动判断位置*/ 'auto' | /*位于下方*/ 'bottom' | /*位于上方*/ 'top';
|
|
94
94
|
/**
|
|
95
95
|
* 文本是否右对齐
|
|
96
96
|
*/
|
|
97
97
|
endAligned: boolean;
|
|
98
98
|
/**
|
|
99
|
-
*
|
|
99
|
+
* 选择框的前缀文本。仅在聚焦状态,或选择框有值时才会显示。也可以通过 `slot="prefix"` 设置
|
|
100
100
|
*/
|
|
101
101
|
prefix: string;
|
|
102
102
|
/**
|
|
103
|
-
*
|
|
103
|
+
* 选择框的后缀文本。仅在聚焦状态,或选择框有值时才会显示。也可以通过 `slot="suffix"` 设置
|
|
104
104
|
*/
|
|
105
105
|
suffix?: string;
|
|
106
106
|
/**
|
|
107
|
-
*
|
|
107
|
+
* 选择框的前缀图标的 Material Icons 图标名。也可以通过 `slot="icon"` 设置
|
|
108
108
|
*/
|
|
109
109
|
icon?: string;
|
|
110
110
|
/**
|
|
111
|
-
*
|
|
111
|
+
* 选择框的后缀图标的 Material Icons 图标名。也可以通过 `slot="end-icon"` 设置
|
|
112
112
|
*/
|
|
113
113
|
endIcon?: string;
|
|
114
114
|
/**
|
|
115
|
-
*
|
|
115
|
+
* 表单字段验证失败时,显示在选择框右侧的 Material Icons 图标名。也可以通过 `slot="error-icon"` 设置
|
|
116
116
|
*/
|
|
117
117
|
errorIcon?: string;
|
|
118
118
|
/**
|
|
119
|
-
* 关联的
|
|
119
|
+
* 关联的 `<form>` 元素。此属性值应为同一页面中的一个 `<form>` 元素的 `id`。
|
|
120
120
|
*
|
|
121
|
-
*
|
|
121
|
+
* 如果未指定此属性,则该元素必须是 `<form>` 元素的子元素。通过此属性,你可以将元素放置在页面的任何位置,而不仅仅是 `<form>` 元素的子元素。
|
|
122
122
|
*/
|
|
123
123
|
form?: string;
|
|
124
124
|
/**
|
|
125
|
-
*
|
|
125
|
+
* 是否为只读状态
|
|
126
126
|
*/
|
|
127
127
|
readonly: boolean;
|
|
128
128
|
/**
|
|
@@ -148,11 +148,11 @@ export declare class Select extends Select_base implements FormControl {
|
|
|
148
148
|
private readonly hasSlotController;
|
|
149
149
|
private readonly definedController;
|
|
150
150
|
/**
|
|
151
|
-
*
|
|
151
|
+
* 表单验证状态对象,具体参见 [`ValidityState`](https://developer.mozilla.org/zh-CN/docs/Web/API/ValidityState)
|
|
152
152
|
*/
|
|
153
153
|
get validity(): ValidityState;
|
|
154
154
|
/**
|
|
155
|
-
*
|
|
155
|
+
* 如果表单验证未通过,此属性将包含提示信息。如果验证通过,此属性将为空字符串
|
|
156
156
|
*/
|
|
157
157
|
get validationMessage(): string;
|
|
158
158
|
protected get focusElement(): HTMLElement;
|
|
@@ -160,19 +160,19 @@ export declare class Select extends Select_base implements FormControl {
|
|
|
160
160
|
connectedCallback(): void;
|
|
161
161
|
disconnectedCallback(): void;
|
|
162
162
|
/**
|
|
163
|
-
*
|
|
163
|
+
* 检查表单字段是否通过验证。如果未通过,返回 `false` 并触发 `invalid` 事件;如果通过,返回 `true`
|
|
164
164
|
*/
|
|
165
165
|
checkValidity(): boolean;
|
|
166
166
|
/**
|
|
167
|
-
*
|
|
167
|
+
* 检查表单字段是否通过验证。如果未通过,返回 `false` 并触发 `invalid` 事件;如果通过,返回 `true`。
|
|
168
168
|
*
|
|
169
|
-
*
|
|
169
|
+
* 如果验证未通过,还会在组件上显示验证失败的提示。
|
|
170
170
|
*/
|
|
171
171
|
reportValidity(): boolean;
|
|
172
172
|
/**
|
|
173
|
-
*
|
|
173
|
+
* 设置自定义的错误提示文本。只要这个文本不为空,就表示字段未通过验证
|
|
174
174
|
*
|
|
175
|
-
* @param message
|
|
175
|
+
* @param message 自定义的错误提示文本
|
|
176
176
|
*/
|
|
177
177
|
setCustomValidity(message: string): void;
|
|
178
178
|
protected firstUpdated(changedProperties: PropertyValues): void;
|
|
@@ -192,6 +192,13 @@ export declare class Select extends Select_base implements FormControl {
|
|
|
192
192
|
*/
|
|
193
193
|
private onTextFieldKeyDown;
|
|
194
194
|
}
|
|
195
|
+
export interface SelectEventMap {
|
|
196
|
+
focus: FocusEvent;
|
|
197
|
+
blur: FocusEvent;
|
|
198
|
+
change: CustomEvent<void>;
|
|
199
|
+
invalid: CustomEvent<void>;
|
|
200
|
+
clear: CustomEvent<void>;
|
|
201
|
+
}
|
|
195
202
|
declare global {
|
|
196
203
|
interface HTMLElementTagNameMap {
|
|
197
204
|
'mdui-select': Select;
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { __decorate } from "tslib";
|
|
2
|
-
import { html,
|
|
2
|
+
import { html, nothing } from 'lit';
|
|
3
3
|
import { customElement, property, queryAssignedElements, state, } from 'lit/decorators.js';
|
|
4
4
|
import { ifDefined } from 'lit/directives/if-defined.js';
|
|
5
5
|
import { map } from 'lit/directives/map.js';
|
|
6
6
|
import { createRef, ref } from 'lit/directives/ref.js';
|
|
7
7
|
import { when } from 'lit/directives/when.js';
|
|
8
8
|
import { isString } from '@mdui/jq/shared/helper.js';
|
|
9
|
+
import { MduiElement } from '@mdui/shared/base/mdui-element.js';
|
|
9
10
|
import { DefinedController } from '@mdui/shared/controllers/defined.js';
|
|
10
11
|
import { FormController, formResets } from '@mdui/shared/controllers/form.js';
|
|
11
12
|
import { HasSlotController } from '@mdui/shared/controllers/has-slot.js';
|
|
12
13
|
import { defaultValue } from '@mdui/shared/decorators/default-value.js';
|
|
13
14
|
import { booleanConverter } from '@mdui/shared/helpers/decorator.js';
|
|
14
|
-
import { emit } from '@mdui/shared/helpers/event.js';
|
|
15
15
|
import { observeResize } from '@mdui/shared/helpers/observeResize.js';
|
|
16
16
|
import { componentStyle } from '@mdui/shared/lit-styles/component-style.js';
|
|
17
17
|
import { FocusableMixin } from '@mdui/shared/mixins/focusable.js';
|
|
@@ -21,7 +21,7 @@ import '../menu.js';
|
|
|
21
21
|
import '../text-field.js';
|
|
22
22
|
import { style } from './style.js';
|
|
23
23
|
/**
|
|
24
|
-
* @summary
|
|
24
|
+
* @summary 选择框组件。需配合 `<mdui-menu-item>` 组件使用
|
|
25
25
|
*
|
|
26
26
|
* ```html
|
|
27
27
|
* <mdui-select>
|
|
@@ -34,7 +34,7 @@ import { style } from './style.js';
|
|
|
34
34
|
* @event blur - 失去焦点时触发
|
|
35
35
|
* @event change - 选中的值变更时触发
|
|
36
36
|
* @event invalid - 表单字段验证未通过时触发
|
|
37
|
-
* @event clear - 在点击由 `clearable` 属性生成的清空按钮时触发。可以通过调用 `event.preventDefault()`
|
|
37
|
+
* @event clear - 在点击由 `clearable` 属性生成的清空按钮时触发。可以通过调用 `event.preventDefault()` 阻止清空选择框
|
|
38
38
|
*
|
|
39
39
|
* @slot - `<mdui-menu-item>` 元素
|
|
40
40
|
* @slot icon - 左侧图标
|
|
@@ -49,14 +49,14 @@ import { style } from './style.js';
|
|
|
49
49
|
* @csspart text-field - 文本框,即 [`<mdui-text-field>`](/docs/2/components/text-field) 元素
|
|
50
50
|
* @csspart menu - 下拉菜单,即 [`<mdui-menu>`](/docs/2/components/menu) 元素
|
|
51
51
|
*/
|
|
52
|
-
let Select = class Select extends FocusableMixin(
|
|
52
|
+
let Select = class Select extends FocusableMixin(MduiElement) {
|
|
53
53
|
constructor() {
|
|
54
54
|
super(...arguments);
|
|
55
55
|
/**
|
|
56
|
-
*
|
|
56
|
+
* 选择框的样式。可选值包括:
|
|
57
57
|
*
|
|
58
|
-
* * `filled
|
|
59
|
-
* * `outlined
|
|
58
|
+
* * `filled`:带背景色的选择框,视觉效果较强
|
|
59
|
+
* * `outlined`:带边框的选择框,视觉效果较弱
|
|
60
60
|
*/
|
|
61
61
|
this.variant = 'filled';
|
|
62
62
|
/**
|
|
@@ -64,14 +64,13 @@ let Select = class Select extends FocusableMixin(LitElement) {
|
|
|
64
64
|
*/
|
|
65
65
|
this.multiple = false;
|
|
66
66
|
/**
|
|
67
|
-
*
|
|
67
|
+
* 选择框的名称,将与表单数据一起提交
|
|
68
68
|
*/
|
|
69
69
|
this.name = '';
|
|
70
70
|
/**
|
|
71
|
-
*
|
|
71
|
+
* 选择框的值,将与表单数据一起提交。
|
|
72
72
|
*
|
|
73
|
-
*
|
|
74
|
-
* HTML 属性只能设置字符串值;如果需要设置数组值,请通过 JavaScript 设置
|
|
73
|
+
* 如果未指定 `multiple` 属性,该值为字符串;如果指定了 `multiple` 属性,该值为字符串数组。HTML 属性只能设置字符串值;如果需要设置数组值,请通过 JavaScript 属性设置。
|
|
75
74
|
*/
|
|
76
75
|
this.value = '';
|
|
77
76
|
/**
|
|
@@ -79,13 +78,13 @@ let Select = class Select extends FocusableMixin(LitElement) {
|
|
|
79
78
|
*/
|
|
80
79
|
this.defaultValue = '';
|
|
81
80
|
/**
|
|
82
|
-
*
|
|
81
|
+
* 是否可以清空选择框
|
|
83
82
|
*/
|
|
84
83
|
this.clearable = false;
|
|
85
84
|
/**
|
|
86
|
-
*
|
|
85
|
+
* 选择框的位置。可选值包括:
|
|
87
86
|
*
|
|
88
|
-
* * `auto
|
|
87
|
+
* * `auto`:自动判断位置
|
|
89
88
|
* * `bottom`:位于下方
|
|
90
89
|
* * `top`:位于上方
|
|
91
90
|
*/
|
|
@@ -95,7 +94,7 @@ let Select = class Select extends FocusableMixin(LitElement) {
|
|
|
95
94
|
*/
|
|
96
95
|
this.endAligned = false;
|
|
97
96
|
/**
|
|
98
|
-
*
|
|
97
|
+
* 是否为只读状态
|
|
99
98
|
*/
|
|
100
99
|
this.readonly = false;
|
|
101
100
|
/**
|
|
@@ -122,13 +121,13 @@ let Select = class Select extends FocusableMixin(LitElement) {
|
|
|
122
121
|
});
|
|
123
122
|
}
|
|
124
123
|
/**
|
|
125
|
-
*
|
|
124
|
+
* 表单验证状态对象,具体参见 [`ValidityState`](https://developer.mozilla.org/zh-CN/docs/Web/API/ValidityState)
|
|
126
125
|
*/
|
|
127
126
|
get validity() {
|
|
128
127
|
return this.hiddenInputRef.value.validity;
|
|
129
128
|
}
|
|
130
129
|
/**
|
|
131
|
-
*
|
|
130
|
+
* 如果表单验证未通过,此属性将包含提示信息。如果验证通过,此属性将为空字符串
|
|
132
131
|
*/
|
|
133
132
|
get validationMessage() {
|
|
134
133
|
return this.hiddenInputRef.value.validationMessage;
|
|
@@ -159,12 +158,12 @@ let Select = class Select extends FocusableMixin(LitElement) {
|
|
|
159
158
|
this.observeResize?.unobserve();
|
|
160
159
|
}
|
|
161
160
|
/**
|
|
162
|
-
*
|
|
161
|
+
* 检查表单字段是否通过验证。如果未通过,返回 `false` 并触发 `invalid` 事件;如果通过,返回 `true`
|
|
163
162
|
*/
|
|
164
163
|
checkValidity() {
|
|
165
164
|
const valid = this.hiddenInputRef.value.checkValidity();
|
|
166
165
|
if (!valid) {
|
|
167
|
-
emit(
|
|
166
|
+
this.emit('invalid', {
|
|
168
167
|
bubbles: false,
|
|
169
168
|
cancelable: true,
|
|
170
169
|
composed: false,
|
|
@@ -173,14 +172,14 @@ let Select = class Select extends FocusableMixin(LitElement) {
|
|
|
173
172
|
return valid;
|
|
174
173
|
}
|
|
175
174
|
/**
|
|
176
|
-
*
|
|
175
|
+
* 检查表单字段是否通过验证。如果未通过,返回 `false` 并触发 `invalid` 事件;如果通过,返回 `true`。
|
|
177
176
|
*
|
|
178
|
-
*
|
|
177
|
+
* 如果验证未通过,还会在组件上显示验证失败的提示。
|
|
179
178
|
*/
|
|
180
179
|
reportValidity() {
|
|
181
180
|
this.invalid = !this.hiddenInputRef.value.reportValidity();
|
|
182
181
|
if (this.invalid) {
|
|
183
|
-
emit(
|
|
182
|
+
this.emit('invalid', {
|
|
184
183
|
bubbles: false,
|
|
185
184
|
cancelable: true,
|
|
186
185
|
composed: false,
|
|
@@ -190,9 +189,9 @@ let Select = class Select extends FocusableMixin(LitElement) {
|
|
|
190
189
|
return !this.invalid;
|
|
191
190
|
}
|
|
192
191
|
/**
|
|
193
|
-
*
|
|
192
|
+
* 设置自定义的错误提示文本。只要这个文本不为空,就表示字段未通过验证
|
|
194
193
|
*
|
|
195
|
-
* @param message
|
|
194
|
+
* @param message 自定义的错误提示文本
|
|
196
195
|
*/
|
|
197
196
|
setCustomValidity(message) {
|
|
198
197
|
this.hiddenInputRef.value.setCustomValidity(message);
|
|
@@ -11,7 +11,7 @@ import type { CSSResultGroup, PropertyValues, TemplateResult } from 'lit';
|
|
|
11
11
|
*
|
|
12
12
|
* @event focus - 获得焦点时触发
|
|
13
13
|
* @event blur - 失去焦点时触发
|
|
14
|
-
* @event change -
|
|
14
|
+
* @event change - 在值发生变更,且失去焦点时,将触发该事件
|
|
15
15
|
* @event input - 值变更时触发
|
|
16
16
|
* @event invalid - 表单字段验证未通过时触发
|
|
17
17
|
*
|
|
@@ -21,7 +21,7 @@ import type { CSSResultGroup, PropertyValues, TemplateResult } from 'lit';
|
|
|
21
21
|
* @csspart label 提示文本
|
|
22
22
|
* @csspart tickmark - 刻度标记
|
|
23
23
|
*/
|
|
24
|
-
export declare class Slider extends SliderBase implements FormControl {
|
|
24
|
+
export declare class Slider extends SliderBase<SliderEventMap> implements FormControl {
|
|
25
25
|
static styles: CSSResultGroup;
|
|
26
26
|
/**
|
|
27
27
|
* 滑块的值,将于表单数据一起提交
|
|
@@ -46,6 +46,13 @@ export declare class Slider extends SliderBase implements FormControl {
|
|
|
46
46
|
private updateStyle;
|
|
47
47
|
private onInput;
|
|
48
48
|
}
|
|
49
|
+
export interface SliderEventMap {
|
|
50
|
+
focus: FocusEvent;
|
|
51
|
+
blur: FocusEvent;
|
|
52
|
+
change: CustomEvent<void>;
|
|
53
|
+
input: Event;
|
|
54
|
+
invalid: CustomEvent<void>;
|
|
55
|
+
}
|
|
49
56
|
declare global {
|
|
50
57
|
interface HTMLElementTagNameMap {
|
|
51
58
|
'mdui-slider': Slider;
|
|
@@ -21,7 +21,7 @@ import { style } from './style.js';
|
|
|
21
21
|
*
|
|
22
22
|
* @event focus - 获得焦点时触发
|
|
23
23
|
* @event blur - 失去焦点时触发
|
|
24
|
-
* @event change -
|
|
24
|
+
* @event change - 在值发生变更,且失去焦点时,将触发该事件
|
|
25
25
|
* @event input - 值变更时触发
|
|
26
26
|
* @event invalid - 表单字段验证未通过时触发
|
|
27
27
|
*
|
|
@@ -49,7 +49,8 @@ let Slider = class Slider extends SliderBase {
|
|
|
49
49
|
get rippleElement() {
|
|
50
50
|
return this.rippleRef.value;
|
|
51
51
|
}
|
|
52
|
-
onValueChange() {
|
|
52
|
+
async onValueChange() {
|
|
53
|
+
this.value = this.fixValue(this.value);
|
|
53
54
|
// reset 引起的值变更,不执行验证;直接修改值引起的变更,需要进行验证
|
|
54
55
|
const form = this.formController.getForm();
|
|
55
56
|
if (form && formResets.get(form)?.has(this)) {
|
|
@@ -57,20 +58,14 @@ let Slider = class Slider extends SliderBase {
|
|
|
57
58
|
formResets.get(form).delete(this);
|
|
58
59
|
}
|
|
59
60
|
else {
|
|
61
|
+
await this.updateComplete;
|
|
60
62
|
this.invalid = !this.inputRef.value.checkValidity();
|
|
61
63
|
}
|
|
62
|
-
this.inputRef.value.value = this.value.toString();
|
|
63
|
-
this.value = parseFloat(this.inputRef.value.value);
|
|
64
64
|
this.updateStyle();
|
|
65
65
|
}
|
|
66
66
|
connectedCallback() {
|
|
67
67
|
super.connectedCallback();
|
|
68
|
-
|
|
69
|
-
this.value = this.min;
|
|
70
|
-
}
|
|
71
|
-
if (this.value > this.max) {
|
|
72
|
-
this.value = this.max;
|
|
73
|
-
}
|
|
68
|
+
this.value = this.fixValue(this.value);
|
|
74
69
|
}
|
|
75
70
|
firstUpdated(changedProperties) {
|
|
76
71
|
super.firstUpdated(changedProperties);
|