mdui 2.0.1 → 2.0.3

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.
Files changed (127) hide show
  1. package/LICENSE +21 -21
  2. package/components/avatar/index.d.ts +4 -2
  3. package/components/avatar/index.js +4 -2
  4. package/components/badge/index.d.ts +4 -2
  5. package/components/badge/index.js +4 -2
  6. package/components/bottom-app-bar/index.d.ts +9 -3
  7. package/components/bottom-app-bar/index.js +9 -9
  8. package/components/button/button-base.d.ts +5 -5
  9. package/components/button/button-base.js +22 -19
  10. package/components/button/index.d.ts +6 -1
  11. package/components/button/index.js +2 -1
  12. package/components/button-icon/index.d.ts +7 -1
  13. package/components/button-icon/index.js +3 -3
  14. package/components/card/index.d.ts +8 -4
  15. package/components/card/index.js +7 -3
  16. package/components/checkbox/index.d.ts +10 -3
  17. package/components/checkbox/index.js +13 -16
  18. package/components/checkbox/style.js +1 -1
  19. package/components/chip/index.d.ts +8 -1
  20. package/components/chip/index.js +5 -5
  21. package/components/circular-progress/index.d.ts +4 -2
  22. package/components/circular-progress/index.js +5 -4
  23. package/components/collapse/collapse-item-style.js +1 -1
  24. package/components/collapse/collapse-item.d.ts +15 -3
  25. package/components/collapse/collapse-item.js +26 -23
  26. package/components/collapse/collapse.d.ts +16 -8
  27. package/components/collapse/collapse.js +61 -38
  28. package/components/dialog/index.d.ts +12 -4
  29. package/components/dialog/index.js +36 -36
  30. package/components/divider/index.d.ts +4 -2
  31. package/components/divider/index.js +4 -2
  32. package/components/dropdown/index.d.ts +13 -7
  33. package/components/dropdown/index.js +70 -63
  34. package/components/fab/index.d.ts +7 -1
  35. package/components/fab/index.js +10 -5
  36. package/components/icon/index.d.ts +4 -2
  37. package/components/icon/index.js +4 -2
  38. package/components/layout/helper.d.ts +5 -6
  39. package/components/layout/helper.js +42 -48
  40. package/components/layout/layout-item-base.d.ts +3 -2
  41. package/components/layout/layout-item-base.js +3 -4
  42. package/components/layout/layout-item.d.ts +4 -3
  43. package/components/layout/layout-item.js +3 -3
  44. package/components/layout/layout-main.d.ts +4 -2
  45. package/components/layout/layout-main.js +4 -2
  46. package/components/layout/layout.d.ts +4 -2
  47. package/components/layout/layout.js +4 -2
  48. package/components/linear-progress/index.d.ts +4 -2
  49. package/components/linear-progress/index.js +5 -4
  50. package/components/list/list-item-style.js +1 -1
  51. package/components/list/list-item.d.ts +7 -3
  52. package/components/list/list-item.js +5 -3
  53. package/components/list/list-subheader.d.ts +4 -2
  54. package/components/list/list-subheader.js +4 -2
  55. package/components/list/list.d.ts +4 -2
  56. package/components/list/list.js +4 -2
  57. package/components/menu/menu-item.d.ts +12 -3
  58. package/components/menu/menu-item.js +53 -40
  59. package/components/menu/menu.d.ts +9 -3
  60. package/components/menu/menu.js +85 -59
  61. package/components/navigation-bar/navigation-bar-item-style.js +1 -1
  62. package/components/navigation-bar/navigation-bar-item.d.ts +13 -5
  63. package/components/navigation-bar/navigation-bar-item.js +28 -11
  64. package/components/navigation-bar/navigation-bar.d.ts +14 -7
  65. package/components/navigation-bar/navigation-bar.js +58 -49
  66. package/components/navigation-drawer/index.d.ts +13 -2
  67. package/components/navigation-drawer/index.js +69 -49
  68. package/components/navigation-drawer/style.js +1 -1
  69. package/components/navigation-rail/navigation-rail-item-style.js +1 -1
  70. package/components/navigation-rail/navigation-rail-item.d.ts +13 -5
  71. package/components/navigation-rail/navigation-rail-item.js +22 -9
  72. package/components/navigation-rail/navigation-rail.d.ts +8 -6
  73. package/components/navigation-rail/navigation-rail.js +55 -46
  74. package/components/radio/radio-group.d.ts +13 -6
  75. package/components/radio/radio-group.js +69 -59
  76. package/components/radio/radio-style.js +1 -1
  77. package/components/radio/radio.d.ts +11 -5
  78. package/components/radio/radio.js +26 -19
  79. package/components/range-slider/index.d.ts +9 -3
  80. package/components/range-slider/index.js +13 -11
  81. package/components/ripple/index.d.ts +4 -2
  82. package/components/ripple/index.js +4 -2
  83. package/components/ripple/ripple-mixin.d.ts +1 -1
  84. package/components/ripple/ripple-mixin.js +0 -1
  85. package/components/segmented-button/segmented-button-group-style.js +1 -1
  86. package/components/segmented-button/segmented-button-group.d.ts +12 -5
  87. package/components/segmented-button/segmented-button-group.js +92 -77
  88. package/components/segmented-button/segmented-button.d.ts +8 -3
  89. package/components/segmented-button/segmented-button.js +5 -4
  90. package/components/select/index.d.ts +13 -5
  91. package/components/select/index.js +30 -28
  92. package/components/slider/index.d.ts +8 -1
  93. package/components/slider/index.js +11 -18
  94. package/components/slider/slider-base-style.js +1 -1
  95. package/components/slider/slider-base.d.ts +7 -3
  96. package/components/slider/slider-base.js +28 -13
  97. package/components/snackbar/index.d.ts +9 -2
  98. package/components/snackbar/index.js +11 -10
  99. package/components/switch/index.d.ts +10 -3
  100. package/components/switch/index.js +12 -15
  101. package/components/switch/style.js +1 -1
  102. package/components/tabs/tab-panel.d.ts +4 -2
  103. package/components/tabs/tab-panel.js +4 -2
  104. package/components/tabs/tab-style.js +1 -1
  105. package/components/tabs/tab.d.ts +7 -3
  106. package/components/tabs/tab.js +12 -6
  107. package/components/tabs/tabs-style.js +1 -1
  108. package/components/tabs/tabs.d.ts +11 -7
  109. package/components/tabs/tabs.js +57 -40
  110. package/components/text-field/index.d.ts +13 -5
  111. package/components/text-field/index.js +43 -65
  112. package/components/text-field/style.js +1 -1
  113. package/components/tooltip/index.d.ts +14 -7
  114. package/components/tooltip/index.js +45 -38
  115. package/components/top-app-bar/top-app-bar-title-style.js +1 -1
  116. package/components/top-app-bar/top-app-bar-title.d.ts +4 -2
  117. package/components/top-app-bar/top-app-bar-title.js +18 -13
  118. package/components/top-app-bar/top-app-bar.d.ts +9 -3
  119. package/components/top-app-bar/top-app-bar.js +11 -10
  120. package/custom-elements.json +904 -546
  121. package/functions/getTheme.js +3 -3
  122. package/functions/snackbar.js +1 -2
  123. package/functions/utils/colorScheme.js +2 -2
  124. package/mdui.esm.js +8 -8
  125. package/mdui.global.js +8 -8
  126. package/package.json +8 -7
  127. package/web-types.zh-cn.json +1 -1
@@ -1,6 +1,4 @@
1
1
  import '@mdui/jq/methods/css.js';
2
- import '@mdui/jq/methods/find.js';
3
- import '@mdui/jq/methods/get.js';
4
2
  import '@mdui/jq/methods/innerWidth.js';
5
3
  import { LayoutItemBase } from '../layout/layout-item-base.js';
6
4
  import type { LayoutPlacement } from '../layout/helper.js';
@@ -29,7 +27,7 @@ import type { CSSResultGroup, TemplateResult } from 'lit';
29
27
  * @cssprop --shape-corner - 组件的圆角大小。可以指定一个具体的像素值;但更推荐[引用设计令牌](/docs/2/styles/design-tokens#shape-corner)
30
28
  * @cssprop --z-index - 组件的 CSS 的 `z-index` 值
31
29
  */
32
- export declare class NavigationRail extends LayoutItemBase {
30
+ export declare class NavigationRail extends LayoutItemBase<NavigationRailEventMap> {
33
31
  static styles: CSSResultGroup;
34
32
  /**
35
33
  * 当前选中的 `<mdui-navigation-rail-item>` 的值
@@ -62,10 +60,11 @@ export declare class NavigationRail extends LayoutItemBase {
62
60
  */
63
61
  divider: boolean;
64
62
  private activeKey;
63
+ private readonly items;
65
64
  private readonly hasSlotController;
66
- private hasSetDefaultValue;
65
+ private readonly definedController;
66
+ private isInitial;
67
67
  protected get layoutPlacement(): LayoutPlacement;
68
- private get items();
69
68
  private get parentTarget();
70
69
  private get isRight();
71
70
  private get paddingValue();
@@ -77,9 +76,12 @@ export declare class NavigationRail extends LayoutItemBase {
77
76
  disconnectedCallback(): void;
78
77
  protected render(): TemplateResult;
79
78
  private onClick;
80
- private updateActive;
79
+ private updateItems;
81
80
  private onSlotChange;
82
81
  }
82
+ export interface NavigationRailEventMap {
83
+ change: CustomEvent<void>;
84
+ }
83
85
  declare global {
84
86
  interface HTMLElementTagNameMap {
85
87
  'mdui-navigation-rail': NavigationRail;
@@ -1,16 +1,14 @@
1
1
  import { __decorate } from "tslib";
2
2
  import { html } from 'lit';
3
- import { customElement, property, state } from 'lit/decorators.js';
3
+ import { customElement, property, queryAssignedElements, state, } from 'lit/decorators.js';
4
4
  import { when } from 'lit/directives/when.js';
5
5
  import { $ } from '@mdui/jq/$.js';
6
6
  import '@mdui/jq/methods/css.js';
7
- import '@mdui/jq/methods/find.js';
8
- import '@mdui/jq/methods/get.js';
9
7
  import '@mdui/jq/methods/innerWidth.js';
8
+ import { DefinedController } from '@mdui/shared/controllers/defined.js';
10
9
  import { HasSlotController } from '@mdui/shared/controllers/has-slot.js';
11
10
  import { watch } from '@mdui/shared/decorators/watch.js';
12
11
  import { booleanConverter } from '@mdui/shared/helpers/decorator.js';
13
- import { emit } from '@mdui/shared/helpers/event.js';
14
12
  import { componentStyle } from '@mdui/shared/lit-styles/component-style.js';
15
13
  import { LayoutItemBase } from '../layout/layout-item-base.js';
16
14
  import { navigationRailStyle } from './navigation-rail-style.js';
@@ -38,7 +36,7 @@ import { navigationRailStyle } from './navigation-rail-style.js';
38
36
  * @cssprop --shape-corner - 组件的圆角大小。可以指定一个具体的像素值;但更推荐[引用设计令牌](/docs/2/styles/design-tokens#shape-corner)
39
37
  * @cssprop --z-index - 组件的 CSS 的 `z-index` 值
40
38
  */
41
- export let NavigationRail = class NavigationRail extends LayoutItemBase {
39
+ let NavigationRail = class NavigationRail extends LayoutItemBase {
42
40
  constructor() {
43
41
  super(...arguments);
44
42
  /**
@@ -70,18 +68,15 @@ export let NavigationRail = class NavigationRail extends LayoutItemBase {
70
68
  // 因为 navigation-rail-item 的 value 可能会重复,所以在每个 navigation-rail-item 元素上都添加了一个唯一的 key,通过 activeKey 来记录激活状态的 key
71
69
  this.activeKey = 0;
72
70
  this.hasSlotController = new HasSlotController(this, 'top', 'bottom');
73
- // 是否已完成初始 value 的设置。首次设置初始值时,不触发 change 事件
74
- this.hasSetDefaultValue = false;
71
+ this.definedController = new DefinedController(this, {
72
+ relatedElements: ['mdui-navigation-rail-item'],
73
+ });
74
+ // 是否是初始状态,初始状态不触发事件,不执行动画
75
+ this.isInitial = true;
75
76
  }
76
77
  get layoutPlacement() {
77
78
  return this.placement;
78
79
  }
79
- // 所有的子项元素
80
- get items() {
81
- return $(this)
82
- .find('mdui-navigation-rail-item')
83
- .get();
84
- }
85
80
  get parentTarget() {
86
81
  return this.contained || this.isParentLayout
87
82
  ? this.parentElement
@@ -95,28 +90,27 @@ export let NavigationRail = class NavigationRail extends LayoutItemBase {
95
90
  ? this.offsetWidth
96
91
  : undefined;
97
92
  }
98
- onActiveKeyChange() {
93
+ async onActiveKeyChange() {
94
+ await this.definedController.whenDefined();
99
95
  // 根据 activeKey 读取对应 navigation-rail-item 的值
100
96
  const item = this.items.find((item) => item.key === this.activeKey);
101
- this.value = item === null || item === void 0 ? void 0 : item.value;
102
- if (this.hasSetDefaultValue) {
103
- emit(this, 'change');
104
- }
105
- else {
106
- this.hasSetDefaultValue = true;
97
+ this.value = item?.value;
98
+ if (!this.isInitial) {
99
+ this.emit('change');
107
100
  }
108
101
  }
109
- onValueChange() {
110
- var _a;
102
+ async onValueChange() {
103
+ this.isInitial = !this.hasUpdated;
104
+ await this.definedController.whenDefined();
111
105
  const item = this.items.find((item) => item.value === this.value);
112
- this.activeKey = (_a = item === null || item === void 0 ? void 0 : item.key) !== null && _a !== void 0 ? _a : 0;
113
- this.updateActive();
106
+ this.activeKey = item?.key ?? 0;
107
+ this.updateItems();
114
108
  }
115
- // 首次渲染在 @watch('placement') 中已经执行,这里跳过
116
- onContainedChange() {
109
+ async onContainedChange() {
117
110
  if (this.isParentLayout) {
118
111
  return;
119
112
  }
113
+ await this.definedController.whenDefined();
120
114
  $(document.body).css({
121
115
  paddingLeft: this.contained || this.isRight ? null : this.paddingValue,
122
116
  paddingRight: this.contained || !this.isRight ? null : this.paddingValue,
@@ -126,32 +120,33 @@ export let NavigationRail = class NavigationRail extends LayoutItemBase {
126
120
  paddingRight: this.contained && this.isRight ? this.paddingValue : null,
127
121
  });
128
122
  }
129
- onPlacementChange() {
130
- var _a;
131
- (_a = this.layoutManager) === null || _a === void 0 ? void 0 : _a.updateLayout(this);
123
+ async onPlacementChange() {
124
+ await this.definedController.whenDefined();
125
+ this.layoutManager?.updateLayout(this);
132
126
  this.items.forEach((item) => {
133
127
  item.placement = this.placement;
134
128
  });
135
- if (this.isParentLayout) {
136
- return;
129
+ if (!this.isParentLayout) {
130
+ $(this.parentTarget).css({
131
+ paddingLeft: this.isRight ? null : this.paddingValue,
132
+ paddingRight: this.isRight ? this.paddingValue : null,
133
+ });
137
134
  }
138
- $(this.parentTarget).css({
139
- paddingLeft: this.isRight ? null : this.paddingValue,
140
- paddingRight: this.isRight ? this.paddingValue : null,
141
- });
142
135
  }
143
136
  connectedCallback() {
144
137
  super.connectedCallback();
145
138
  if (!this.isParentLayout) {
146
- $(this.parentTarget).css({
147
- paddingLeft: this.isRight ? null : this.paddingValue,
148
- paddingRight: this.isRight ? this.paddingValue : null,
139
+ this.definedController.whenDefined().then(() => {
140
+ $(this.parentTarget).css({
141
+ paddingLeft: this.isRight ? null : this.paddingValue,
142
+ paddingRight: this.isRight ? this.paddingValue : null,
143
+ });
149
144
  });
150
145
  }
151
146
  }
152
147
  disconnectedCallback() {
153
148
  super.disconnectedCallback();
154
- if (!this.isParentLayout) {
149
+ if (!this.isParentLayout && this.definedController.isDefined()) {
155
150
  $(this.parentTarget).css({
156
151
  paddingLeft: this.isRight ? undefined : null,
157
152
  paddingRight: this.isRight ? null : undefined,
@@ -170,17 +165,24 @@ export let NavigationRail = class NavigationRail extends LayoutItemBase {
170
165
  }
171
166
  const target = event.target;
172
167
  const item = target.closest('mdui-navigation-rail-item');
168
+ if (!item) {
169
+ return;
170
+ }
173
171
  this.activeKey = item.key;
174
- this.updateActive();
175
- }
176
- updateActive() {
177
- this.items.forEach((item) => (item.active = this.activeKey === item.key));
172
+ this.isInitial = false;
173
+ this.updateItems();
178
174
  }
179
- onSlotChange() {
175
+ updateItems() {
180
176
  this.items.forEach((item) => {
177
+ item.active = this.activeKey === item.key;
181
178
  item.placement = this.placement;
179
+ item.isInitial = this.isInitial;
182
180
  });
183
181
  }
182
+ async onSlotChange() {
183
+ await this.definedController.whenDefined();
184
+ this.updateItems();
185
+ }
184
186
  };
185
187
  NavigationRail.styles = [
186
188
  componentStyle,
@@ -214,7 +216,13 @@ __decorate([
214
216
  state()
215
217
  ], NavigationRail.prototype, "activeKey", void 0);
216
218
  __decorate([
217
- watch('activeKey')
219
+ queryAssignedElements({
220
+ selector: 'mdui-navigation-rail-item',
221
+ flatten: true,
222
+ })
223
+ ], NavigationRail.prototype, "items", void 0);
224
+ __decorate([
225
+ watch('activeKey', true)
218
226
  ], NavigationRail.prototype, "onActiveKeyChange", null);
219
227
  __decorate([
220
228
  watch('value')
@@ -223,8 +231,9 @@ __decorate([
223
231
  watch('contained', true)
224
232
  ], NavigationRail.prototype, "onContainedChange", null);
225
233
  __decorate([
226
- watch('placement')
234
+ watch('placement', true)
227
235
  ], NavigationRail.prototype, "onPlacementChange", null);
228
236
  NavigationRail = __decorate([
229
237
  customElement('mdui-navigation-rail')
230
238
  ], NavigationRail);
239
+ export { NavigationRail };
@@ -1,7 +1,7 @@
1
- import { LitElement } from 'lit';
2
1
  import '@mdui/jq/methods/closest.js';
3
2
  import '@mdui/jq/methods/find.js';
4
3
  import '@mdui/jq/methods/get.js';
4
+ import { MduiElement } from '@mdui/shared/base/mdui-element.js';
5
5
  import type { FormControl } from '@mdui/jq/shared/form.js';
6
6
  import type { CSSResultGroup, TemplateResult } from 'lit';
7
7
  /**
@@ -20,7 +20,7 @@ import type { CSSResultGroup, TemplateResult } from 'lit';
20
20
  *
21
21
  * @slot - `<mdui-radio>` 元素
22
22
  */
23
- export declare class RadioGroup extends LitElement implements FormControl {
23
+ export declare class RadioGroup extends MduiElement<RadioGroupEventMap> implements FormControl {
24
24
  static styles: CSSResultGroup;
25
25
  /**
26
26
  * 是否为禁用状态
@@ -52,8 +52,10 @@ export declare class RadioGroup extends LitElement implements FormControl {
52
52
  * 是否验证未通过
53
53
  */
54
54
  private invalid;
55
+ private isInitial;
55
56
  private readonly inputRef;
56
57
  private readonly formController;
58
+ private readonly definedController;
57
59
  /**
58
60
  * 表单验证状态对象
59
61
  */
@@ -62,11 +64,10 @@ export declare class RadioGroup extends LitElement implements FormControl {
62
64
  * 表单验证的错误提示信息
63
65
  */
64
66
  get validationMessage(): string;
65
- private get radios();
66
- private get radiosEnabled();
67
+ private get items();
68
+ private get itemsEnabled();
67
69
  private onValueChange;
68
70
  private onInvalidChange;
69
- private onDisabledChange;
70
71
  /**
71
72
  * 检查表单字段是否验证通过。若未通过则返回 `false`,并触发 `invalid` 事件;若验证通过,则返回 `true`
72
73
  */
@@ -85,7 +86,7 @@ export declare class RadioGroup extends LitElement implements FormControl {
85
86
  setCustomValidity(message: string): void;
86
87
  protected render(): TemplateResult;
87
88
  private updateRadioFocusable;
88
- private onRadioClick;
89
+ private onClick;
89
90
  /**
90
91
  * 在内部的 `<mdui-radio>` 上按下按键时,在 `<mdui-radio>` 之间切换焦点
91
92
  */
@@ -95,6 +96,12 @@ export declare class RadioGroup extends LitElement implements FormControl {
95
96
  * slot 中的 mdui-radio 的 checked 变更时触发的事件
96
97
  */
97
98
  private onCheckedChange;
99
+ private updateItems;
100
+ }
101
+ export interface RadioGroupEventMap {
102
+ change: CustomEvent<void>;
103
+ input: CustomEvent<void>;
104
+ invalid: CustomEvent<void>;
98
105
  }
99
106
  declare global {
100
107
  interface HTMLElementTagNameMap {
@@ -1,18 +1,18 @@
1
1
  import { __decorate } from "tslib";
2
- import { html, LitElement } from 'lit';
3
- import { customElement, property } from 'lit/decorators.js';
2
+ import { html } from 'lit';
3
+ import { customElement, property, state } from 'lit/decorators.js';
4
4
  import { ifDefined } from 'lit/directives/if-defined.js';
5
5
  import { createRef, ref } from 'lit/directives/ref.js';
6
6
  import { $ } from '@mdui/jq/$.js';
7
7
  import '@mdui/jq/methods/closest.js';
8
8
  import '@mdui/jq/methods/find.js';
9
9
  import '@mdui/jq/methods/get.js';
10
- import { isNodeName } from '@mdui/jq/shared/helper.js';
10
+ import { MduiElement } from '@mdui/shared/base/mdui-element.js';
11
+ import { DefinedController } from '@mdui/shared/controllers/defined.js';
11
12
  import { FormController, formResets } from '@mdui/shared/controllers/form.js';
12
13
  import { defaultValue } from '@mdui/shared/decorators/default-value.js';
13
14
  import { watch } from '@mdui/shared/decorators/watch.js';
14
15
  import { booleanConverter } from '@mdui/shared/helpers/decorator.js';
15
- import { emit } from '@mdui/shared/helpers/event.js';
16
16
  import { componentStyle } from '@mdui/shared/lit-styles/component-style.js';
17
17
  import { radioGroupStyle } from './radio-group-style.js';
18
18
  /**
@@ -31,7 +31,7 @@ import { radioGroupStyle } from './radio-group-style.js';
31
31
  *
32
32
  * @slot - `<mdui-radio>` 元素
33
33
  */
34
- export let RadioGroup = class RadioGroup extends LitElement {
34
+ let RadioGroup = class RadioGroup extends MduiElement {
35
35
  constructor() {
36
36
  super(...arguments);
37
37
  /**
@@ -58,8 +58,13 @@ export let RadioGroup = class RadioGroup extends LitElement {
58
58
  * 是否验证未通过
59
59
  */
60
60
  this.invalid = false;
61
+ // 是否是初始状态,初始状态不显示动画
62
+ this.isInitial = true;
61
63
  this.inputRef = createRef();
62
64
  this.formController = new FormController(this);
65
+ this.definedController = new DefinedController(this, {
66
+ relatedElements: ['mdui-radio'],
67
+ });
63
68
  }
64
69
  /**
65
70
  * 表单验证状态对象
@@ -73,24 +78,26 @@ export let RadioGroup = class RadioGroup extends LitElement {
73
78
  get validationMessage() {
74
79
  return this.inputRef.value.validationMessage;
75
80
  }
76
- get radios() {
81
+ // 为了使 <mdui-radio> 可以不是该组件的直接子元素,这里不用 @queryAssignedElements()
82
+ get items() {
77
83
  return $(this).find('mdui-radio').get();
78
84
  }
79
- get radiosEnabled() {
85
+ get itemsEnabled() {
80
86
  return $(this)
81
87
  .find('mdui-radio:not([disabled])')
82
88
  .get();
83
89
  }
84
90
  async onValueChange() {
85
- var _a;
86
- emit(this, 'input');
87
- emit(this, 'change');
88
- this.radios.forEach((radio) => (radio.checked = radio.value === this.value));
91
+ this.isInitial = false;
92
+ await this.definedController.whenDefined();
93
+ this.emit('input');
94
+ this.emit('change');
95
+ this.updateItems();
89
96
  this.updateRadioFocusable();
90
97
  await this.updateComplete;
91
98
  // reset 引起的值变更,不执行验证;直接修改值引起的变更,需要进行验证
92
99
  const form = this.formController.getForm();
93
- if (form && ((_a = formResets.get(form)) === null || _a === void 0 ? void 0 : _a.has(this))) {
100
+ if (form && formResets.get(form)?.has(this)) {
94
101
  this.invalid = false;
95
102
  formResets.get(form).delete(this);
96
103
  }
@@ -98,11 +105,9 @@ export let RadioGroup = class RadioGroup extends LitElement {
98
105
  this.invalid = !this.inputRef.value.checkValidity();
99
106
  }
100
107
  }
101
- onInvalidChange() {
102
- this.radiosEnabled.forEach((radio) => (radio.invalid = this.invalid));
103
- }
104
- onDisabledChange() {
105
- this.radios.forEach((radio) => (radio.groupDisabled = this.disabled));
108
+ async onInvalidChange() {
109
+ await this.definedController.whenDefined();
110
+ this.updateItems();
106
111
  }
107
112
  /**
108
113
  * 检查表单字段是否验证通过。若未通过则返回 `false`,并触发 `invalid` 事件;若验证通过,则返回 `true`
@@ -110,7 +115,7 @@ export let RadioGroup = class RadioGroup extends LitElement {
110
115
  checkValidity() {
111
116
  const valid = this.inputRef.value.checkValidity();
112
117
  if (!valid) {
113
- emit(this, 'invalid', {
118
+ this.emit('invalid', {
114
119
  bubbles: false,
115
120
  cancelable: true,
116
121
  composed: false,
@@ -126,13 +131,13 @@ export let RadioGroup = class RadioGroup extends LitElement {
126
131
  reportValidity() {
127
132
  this.invalid = !this.inputRef.value.reportValidity();
128
133
  if (this.invalid) {
129
- const requestInvalid = emit(this, 'invalid', {
134
+ const eventProceeded = this.emit('invalid', {
130
135
  bubbles: false,
131
136
  cancelable: true,
132
137
  composed: false,
133
138
  });
134
- // 调用了 preventDefault() 时,隐藏默认的表单错误提示
135
- if (requestInvalid.defaultPrevented) {
139
+ if (!eventProceeded) {
140
+ // 调用了 preventDefault() 时,隐藏默认的表单错误提示
136
141
  this.inputRef.value.blur();
137
142
  this.inputRef.value.focus();
138
143
  }
@@ -149,63 +154,66 @@ export let RadioGroup = class RadioGroup extends LitElement {
149
154
  this.invalid = !this.inputRef.value.checkValidity();
150
155
  }
151
156
  render() {
152
- return html `<fieldset><input ${ref(this.inputRef)} type="radio" class="input" name="${ifDefined(this.name)}" value="${ifDefined(this.value)}" .checked="${!!this.value}" .required="${this.required}" tabindex="-1" @keydown="${this.onKeyDown}"><slot @click="${this.onRadioClick}" @keydown="${this.onKeyDown}" @slotchange="${this.onSlotChange}" @change="${this.onCheckedChange}"></slot></fieldset>`;
157
+ return html `<fieldset><input ${ref(this.inputRef)} type="radio" class="input" name="${ifDefined(this.name)}" value="${ifDefined(this.value)}" .checked="${!!this.value}" .required="${this.required}" tabindex="-1" @keydown="${this.onKeyDown}"><slot @click="${this.onClick}" @keydown="${this.onKeyDown}" @slotchange="${this.onSlotChange}" @change="${this.onCheckedChange}"></slot></fieldset>`;
153
158
  }
154
159
  // 更新 mdui-radio 的 checked 后,需要更新可聚焦状态
155
160
  // 同一个 mdui-radio-group 中的多个 mdui-radio,仅有一个可聚焦
156
161
  // 若有已选中的,则已选中的可聚焦;若没有已选中的,则第一个可聚焦
157
162
  updateRadioFocusable() {
158
- const radios = this.radios;
159
- const radioChecked = radios.find((radio) => radio.checked);
160
- if (radioChecked) {
161
- radios.forEach((radio) => (radio.focusable = radio === radioChecked));
163
+ const items = this.items;
164
+ const itemChecked = items.find((item) => item.checked);
165
+ if (itemChecked) {
166
+ items.forEach((item) => {
167
+ item.focusable = item === itemChecked;
168
+ });
162
169
  }
163
170
  else {
164
- this.radiosEnabled.forEach((radio, index) => (radio.focusable = !index));
171
+ this.itemsEnabled.forEach((item, index) => {
172
+ item.focusable = !index;
173
+ });
165
174
  }
166
175
  }
167
- async onRadioClick(event) {
176
+ async onClick(event) {
177
+ await this.definedController.whenDefined();
168
178
  const target = event.target;
169
- const radio = isNodeName(target, 'mdui-radio')
170
- ? target
171
- : $(target).closest('mdui-radio')[0];
172
- if (radio.disabled) {
179
+ const item = target.closest('mdui-radio');
180
+ if (!item || item.disabled) {
173
181
  return;
174
182
  }
175
- this.value = radio.value;
183
+ this.value = item.value;
176
184
  await this.updateComplete;
177
- radio.focus();
185
+ item.focus();
178
186
  }
179
187
  /**
180
188
  * 在内部的 `<mdui-radio>` 上按下按键时,在 `<mdui-radio>` 之间切换焦点
181
189
  */
182
- onKeyDown(event) {
183
- var _a;
190
+ async onKeyDown(event) {
184
191
  if (!['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight', ' '].includes(event.key)) {
185
192
  return;
186
193
  }
187
- const radios = this.radiosEnabled;
188
- const radioChecked = (_a = radios.find((radio) => radio.checked)) !== null && _a !== void 0 ? _a : radios[0];
194
+ event.preventDefault();
195
+ await this.definedController.whenDefined();
196
+ const items = this.itemsEnabled;
197
+ const itemChecked = items.find((item) => item.checked) ?? items[0];
189
198
  const incr = event.key === ' '
190
199
  ? 0
191
200
  : ['ArrowUp', 'ArrowLeft'].includes(event.key)
192
201
  ? -1
193
202
  : 1;
194
- let index = radios.indexOf(radioChecked) + incr;
203
+ let index = items.indexOf(itemChecked) + incr;
195
204
  if (index < 0) {
196
- index = radios.length - 1;
205
+ index = items.length - 1;
197
206
  }
198
- if (index > radios.length - 1) {
207
+ if (index > items.length - 1) {
199
208
  index = 0;
200
209
  }
201
- this.value = radios[index].value;
202
- this.updateComplete.then(() => {
203
- radios[index].focus();
204
- });
205
- event.preventDefault();
210
+ this.value = items[index].value;
211
+ await this.updateComplete;
212
+ items[index].focus();
206
213
  }
207
- onSlotChange() {
208
- this.radios.forEach((radio) => (radio.checked = radio.value === this.value));
214
+ async onSlotChange() {
215
+ await this.definedController.whenDefined();
216
+ this.updateItems();
209
217
  this.updateRadioFocusable();
210
218
  }
211
219
  /**
@@ -213,8 +221,15 @@ export let RadioGroup = class RadioGroup extends LitElement {
213
221
  */
214
222
  onCheckedChange(event) {
215
223
  event.stopPropagation();
216
- const target = event.target;
217
- this.value = target.value;
224
+ }
225
+ // 更新 <mdui-radio> 的状态
226
+ updateItems() {
227
+ this.items.forEach((item) => {
228
+ item.checked = item.value === this.value;
229
+ item.invalid = this.invalid;
230
+ item.groupDisabled = this.disabled;
231
+ item.isInitial = this.isInitial;
232
+ });
218
233
  }
219
234
  };
220
235
  RadioGroup.styles = [
@@ -248,21 +263,16 @@ __decorate([
248
263
  })
249
264
  ], RadioGroup.prototype, "required", void 0);
250
265
  __decorate([
251
- property({
252
- type: Boolean,
253
- reflect: true,
254
- converter: booleanConverter,
255
- })
266
+ state()
256
267
  ], RadioGroup.prototype, "invalid", void 0);
257
268
  __decorate([
258
269
  watch('value', true)
259
270
  ], RadioGroup.prototype, "onValueChange", null);
260
271
  __decorate([
261
- watch('invalid')
262
- ], RadioGroup.prototype, "onInvalidChange", null);
263
- __decorate([
272
+ watch('invalid', true),
264
273
  watch('disabled')
265
- ], RadioGroup.prototype, "onDisabledChange", null);
274
+ ], RadioGroup.prototype, "onInvalidChange", null);
266
275
  RadioGroup = __decorate([
267
276
  customElement('mdui-radio-group')
268
277
  ], RadioGroup);
278
+ export { RadioGroup };
@@ -1,2 +1,2 @@
1
1
  import { css } from 'lit';
2
- export const radioStyle = css `:host{position:relative;display:inline-flex;align-items:center;cursor:pointer;-webkit-tap-highlight-color:transparent;-webkit-user-select:none;user-select:none;touch-action:manipulation;zoom:1;-webkit-user-drag:none;border-radius:.125rem;font-size:var(--mdui-typescale-label-large-size);font-weight:var(--mdui-typescale-label-large-weight);letter-spacing:var(--mdui-typescale-label-large-tracking);line-height:var(--mdui-typescale-label-large-line-height)}.icon{display:flex;position:absolute;font-size:1.5rem;transition-duration:var(--mdui-motion-duration-short4);transition-timing-function:var(--mdui-motion-easing-standard)}.unchecked-icon{transition-property:color;color:rgb(var(--mdui-color-on-surface-variant))}:host([focused]) .unchecked-icon,:host([hover]) .unchecked-icon,:host([pressed]) .unchecked-icon{color:rgb(var(--mdui-color-on-surface))}.checked-icon{opacity:0;transform:scale(.2);transition-property:color,opacity,transform;color:rgb(var(--mdui-color-primary))}.icon .i,::slotted([slot=checked-icon]),::slotted([slot=unchecked-icon]){color:inherit;font-size:inherit}i{position:relative;display:flex;align-items:center;justify-content:center;overflow:hidden;border-radius:50%;width:2.5rem;min-width:2.5rem;height:2.5rem;--mdui-comp-ripple-state-layer-color:var(--mdui-color-on-surface)}.label{display:flex;width:100%;padding-top:.625rem;padding-bottom:.625rem;color:rgb(var(--mdui-color-on-surface));transition:color var(--mdui-motion-duration-short4) var(--mdui-motion-easing-standard)}:host([checked]) i{--mdui-comp-ripple-state-layer-color:var(--mdui-color-primary)}:host([checked]) .icon{color:rgb(var(--mdui-color-primary))}:host([checked]) .checked-icon{opacity:1;transform:scale(.5)}:host([invalid]) i{--mdui-comp-ripple-state-layer-color:var(--mdui-color-error)}:host([invalid]) .icon{color:rgb(var(--mdui-color-error))}:host([invalid]) .label{color:rgb(var(--mdui-color-error))}:host([disabled]),:host([group-disabled]){cursor:default;pointer-events:none}:host([disabled]) .icon,:host([group-disabled]) .icon{color:rgba(var(--mdui-color-on-surface),38%)}:host([disabled]) .label,:host([group-disabled]) .label{color:rgba(var(--mdui-color-on-surface),38%)}`;
2
+ export const radioStyle = css `:host{position:relative;display:inline-flex;align-items:center;cursor:pointer;-webkit-tap-highlight-color:transparent;-webkit-user-select:none;user-select:none;touch-action:manipulation;zoom:1;-webkit-user-drag:none;border-radius:.125rem;font-size:var(--mdui-typescale-label-large-size);font-weight:var(--mdui-typescale-label-large-weight);letter-spacing:var(--mdui-typescale-label-large-tracking);line-height:var(--mdui-typescale-label-large-line-height)}.icon{display:flex;position:absolute;font-size:1.5rem}:not(.initial) .icon{transition-duration:var(--mdui-motion-duration-short4);transition-timing-function:var(--mdui-motion-easing-standard)}.unchecked-icon{transition-property:color;color:rgb(var(--mdui-color-on-surface-variant))}:host([focused]) .unchecked-icon,:host([hover]) .unchecked-icon,:host([pressed]) .unchecked-icon{color:rgb(var(--mdui-color-on-surface))}.checked-icon{opacity:0;transform:scale(.2);transition-property:color,opacity,transform;color:rgb(var(--mdui-color-primary))}.icon .i,::slotted([slot=checked-icon]),::slotted([slot=unchecked-icon]){color:inherit;font-size:inherit}i{position:relative;display:flex;align-items:center;justify-content:center;overflow:hidden;border-radius:50%;width:2.5rem;min-width:2.5rem;height:2.5rem;--mdui-comp-ripple-state-layer-color:var(--mdui-color-on-surface)}.label{display:flex;width:100%;padding-top:.625rem;padding-bottom:.625rem;color:rgb(var(--mdui-color-on-surface))}.label:not(.initial){transition:color var(--mdui-motion-duration-short4) var(--mdui-motion-easing-standard)}:host([checked]) i{--mdui-comp-ripple-state-layer-color:var(--mdui-color-primary)}:host([checked]) .icon{color:rgb(var(--mdui-color-primary))}:host([checked]) .checked-icon{opacity:1;transform:scale(.5)}i.invalid{--mdui-comp-ripple-state-layer-color:var(--mdui-color-error)}i.invalid .icon{color:rgb(var(--mdui-color-error))}.label.invalid{color:rgb(var(--mdui-color-error))}:host([disabled]),:host([group-disabled]){cursor:default;pointer-events:none}:host([disabled]) .icon,:host([group-disabled]) .icon{color:rgba(var(--mdui-color-on-surface),38%)}:host([disabled]) .label,:host([group-disabled]) .label{color:rgba(var(--mdui-color-on-surface),38%)}`;
@@ -1,10 +1,10 @@
1
- import { LitElement } from 'lit';
1
+ import { MduiElement } from '@mdui/shared/base/mdui-element.js';
2
2
  import '@mdui/shared/icons/circle.js';
3
3
  import '@mdui/shared/icons/radio-button-unchecked.js';
4
4
  import '../icon.js';
5
5
  import type { Ripple } from '../ripple/index.js';
6
- import type { CSSResultGroup, TemplateResult } from 'lit';
7
- declare const Radio_base: import("@open-wc/dedupe-mixin").Constructor<import("../ripple/ripple-mixin.js").RippleMixinInterface> & import("@open-wc/dedupe-mixin").Constructor<import("@mdui/shared/mixins/focusable.js").FocusableMixinInterface> & typeof LitElement;
6
+ import type { CSSResultGroup, PropertyValues, TemplateResult } from 'lit';
7
+ declare const Radio_base: import("@open-wc/dedupe-mixin").Constructor<import("../ripple/ripple-mixin.js").RippleMixinInterface> & import("@open-wc/dedupe-mixin").Constructor<import("@mdui/shared/mixins/focusable.js").FocusableMixinInterface> & typeof MduiElement;
8
8
  /**
9
9
  * @summary 单选框组件。需与 `<mdui-radio-group>` 组件配合使用
10
10
  *
@@ -28,7 +28,7 @@ declare const Radio_base: import("@open-wc/dedupe-mixin").Constructor<import("..
28
28
  * @csspart checked-icon 选中状态的图标
29
29
  * @csspart label - 文本
30
30
  */
31
- export declare class Radio extends Radio_base {
31
+ export declare class Radio extends Radio_base<RadioEventMap> {
32
32
  static styles: CSSResultGroup;
33
33
  /**
34
34
  * 当前单选项的值
@@ -53,16 +53,22 @@ export declare class Radio extends Radio_base {
53
53
  protected invalid: boolean;
54
54
  protected groupDisabled: boolean;
55
55
  protected focusable: boolean;
56
+ protected isInitial: boolean;
56
57
  private readonly rippleRef;
57
58
  protected get rippleElement(): Ripple;
58
59
  protected get rippleDisabled(): boolean;
59
60
  protected get focusElement(): HTMLElement;
60
61
  protected get focusDisabled(): boolean;
61
62
  private onCheckedChange;
62
- connectedCallback(): void;
63
+ protected firstUpdated(_changedProperties: PropertyValues): void;
63
64
  protected render(): TemplateResult;
64
65
  private isDisabled;
65
66
  }
67
+ export interface RadioEventMap {
68
+ focus: FocusEvent;
69
+ blur: FocusEvent;
70
+ change: CustomEvent<void>;
71
+ }
66
72
  declare global {
67
73
  interface HTMLElementTagNameMap {
68
74
  'mdui-radio': Radio;