mdui 2.0.0 → 2.0.2

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 (96) hide show
  1. package/components/avatar/index.js +2 -1
  2. package/components/badge/index.js +2 -1
  3. package/components/bottom-app-bar/index.d.ts +2 -2
  4. package/components/bottom-app-bar/index.js +4 -3
  5. package/components/button/button-base.d.ts +2 -2
  6. package/components/button/button-base.js +15 -14
  7. package/components/button/index.js +2 -1
  8. package/components/button-icon/index.js +2 -1
  9. package/components/card/index.d.ts +1 -1
  10. package/components/card/index.js +5 -2
  11. package/components/checkbox/index.js +7 -10
  12. package/components/checkbox/style.js +1 -1
  13. package/components/chip/index.js +2 -1
  14. package/components/circular-progress/index.js +3 -3
  15. package/components/collapse/collapse-item-style.js +1 -1
  16. package/components/collapse/collapse-item.d.ts +2 -1
  17. package/components/collapse/collapse-item.js +23 -20
  18. package/components/collapse/collapse.d.ts +6 -6
  19. package/components/collapse/collapse.js +57 -34
  20. package/components/dialog/index.d.ts +3 -2
  21. package/components/dialog/index.js +27 -23
  22. package/components/divider/index.js +2 -1
  23. package/components/dropdown/index.d.ts +4 -5
  24. package/components/dropdown/index.js +56 -51
  25. package/components/fab/index.d.ts +1 -0
  26. package/components/fab/index.js +10 -5
  27. package/components/icon/index.js +2 -1
  28. package/components/layout/helper.d.ts +5 -6
  29. package/components/layout/helper.js +42 -48
  30. package/components/layout/layout-item-base.js +1 -2
  31. package/components/layout/layout-item.js +3 -3
  32. package/components/layout/layout-main.js +2 -1
  33. package/components/layout/layout.js +2 -1
  34. package/components/linear-progress/index.js +3 -3
  35. package/components/list/list-item.js +3 -2
  36. package/components/list/list-subheader.js +2 -1
  37. package/components/list/list.js +2 -1
  38. package/components/menu/menu-item.d.ts +1 -0
  39. package/components/menu/menu-item.js +45 -28
  40. package/components/menu/menu.d.ts +4 -1
  41. package/components/menu/menu.js +82 -56
  42. package/components/navigation-bar/navigation-bar-item-style.js +1 -1
  43. package/components/navigation-bar/navigation-bar-item.d.ts +6 -2
  44. package/components/navigation-bar/navigation-bar-item.js +26 -10
  45. package/components/navigation-bar/navigation-bar.d.ts +6 -6
  46. package/components/navigation-bar/navigation-bar.js +49 -42
  47. package/components/navigation-drawer/index.d.ts +5 -1
  48. package/components/navigation-drawer/index.js +62 -41
  49. package/components/navigation-rail/navigation-rail-item-style.js +1 -1
  50. package/components/navigation-rail/navigation-rail-item.d.ts +6 -2
  51. package/components/navigation-rail/navigation-rail-item.js +20 -8
  52. package/components/navigation-rail/navigation-rail.d.ts +4 -5
  53. package/components/navigation-rail/navigation-rail.js +51 -44
  54. package/components/radio/radio-group.d.ts +6 -4
  55. package/components/radio/radio-group.js +61 -48
  56. package/components/radio/radio-style.js +1 -1
  57. package/components/radio/radio.d.ts +3 -2
  58. package/components/radio/radio.js +24 -17
  59. package/components/range-slider/index.js +7 -9
  60. package/components/ripple/index.js +2 -1
  61. package/components/segmented-button/segmented-button-group.d.ts +6 -3
  62. package/components/segmented-button/segmented-button-group.js +84 -69
  63. package/components/segmented-button/segmented-button.d.ts +2 -2
  64. package/components/segmented-button/segmented-button.js +5 -4
  65. package/components/select/index.d.ts +2 -2
  66. package/components/select/index.js +26 -24
  67. package/components/slider/index.js +7 -9
  68. package/components/slider/slider-base-style.js +1 -1
  69. package/components/slider/slider-base.js +1 -5
  70. package/components/snackbar/index.js +2 -1
  71. package/components/switch/index.js +6 -9
  72. package/components/switch/style.js +1 -1
  73. package/components/tabs/tab-panel.js +2 -1
  74. package/components/tabs/tab-style.js +1 -1
  75. package/components/tabs/tab.js +10 -5
  76. package/components/tabs/tabs-style.js +1 -1
  77. package/components/tabs/tabs.d.ts +6 -5
  78. package/components/tabs/tabs.js +52 -38
  79. package/components/text-field/index.d.ts +2 -2
  80. package/components/text-field/index.js +32 -54
  81. package/components/text-field/style.js +1 -1
  82. package/components/tooltip/index.d.ts +5 -5
  83. package/components/tooltip/index.js +30 -25
  84. package/components/top-app-bar/top-app-bar-title-style.js +1 -1
  85. package/components/top-app-bar/top-app-bar-title.js +16 -12
  86. package/components/top-app-bar/top-app-bar.d.ts +2 -2
  87. package/components/top-app-bar/top-app-bar.js +6 -4
  88. package/custom-elements.json +3776 -3481
  89. package/functions/getTheme.js +3 -3
  90. package/functions/snackbar.js +1 -2
  91. package/functions/utils/colorScheme.js +2 -2
  92. package/html-data.zh-cn.json +727 -727
  93. package/mdui.esm.js +8 -8
  94. package/mdui.global.js +8 -8
  95. package/package.json +7 -7
  96. package/web-types.zh-cn.json +1265 -1265
@@ -9,8 +9,10 @@ import '@mdui/jq/methods/get.js';
9
9
  import '@mdui/jq/methods/is.js';
10
10
  import '@mdui/jq/methods/parent.js';
11
11
  import '@mdui/jq/methods/parents.js';
12
- import { isString } from '@mdui/jq/shared/helper.js';
12
+ import { isString, isUndefined } from '@mdui/jq/shared/helper.js';
13
+ import { DefinedController } from '@mdui/shared/controllers/defined.js';
13
14
  import { watch } from '@mdui/shared/decorators/watch.js';
15
+ import { arraysEqualIgnoreOrder } from '@mdui/shared/helpers/array.js';
14
16
  import { booleanConverter } from '@mdui/shared/helpers/decorator.js';
15
17
  import { delay } from '@mdui/shared/helpers/delay.js';
16
18
  import { emit } from '@mdui/shared/helpers/event.js';
@@ -39,7 +41,7 @@ import { menuStyle } from './menu-style.js';
39
41
  *
40
42
  * @cssprop --shape-corner - 组件的圆角大小。可以指定一个具体的像素值;但更推荐[引用设计令牌](/docs/2/styles/design-tokens#shape-corner)
41
43
  */
42
- export let Menu = class Menu extends LitElement {
44
+ let Menu = class Menu extends LitElement {
43
45
  constructor() {
44
46
  super(...arguments);
45
47
  /**
@@ -65,10 +67,13 @@ export let Menu = class Menu extends LitElement {
65
67
  this.submenuCloseDelay = 200;
66
68
  // 因为 menu-item 的 value 可能会重复,所有在每一个 menu-item 元素上都加了一个唯一的 key 属性,通过 selectedKeys 来记录选中状态的 key
67
69
  this.selectedKeys = [];
68
- // 是否已完成初始 value 的设置。首次设置初始值时,不触发 change 事件
69
- this.hasSetDefaultValue = false;
70
+ // 是否是初始状态,初始状态不触发 change 事件
71
+ this.isInitial = true;
70
72
  // 最后一次获得焦点的 menu-item 元素。为嵌套菜单时,把不同层级的 menu-item 放到对应索引位的位置
71
73
  this.lastActiveItems = [];
74
+ this.definedController = new DefinedController(this, {
75
+ relatedElements: ['mdui-menu-item'],
76
+ });
72
77
  }
73
78
  // 菜单项元素(包含子菜单中的菜单项)
74
79
  get items() {
@@ -110,7 +115,8 @@ export let Menu = class Menu extends LitElement {
110
115
  : 0;
111
116
  this.lastActiveItems[index] = item;
112
117
  }
113
- onSlotChange() {
118
+ async onSlotChange() {
119
+ await this.definedController.whenDefined();
114
120
  this.items.forEach((item) => {
115
121
  item.dense = this.dense;
116
122
  item.selects = this.selects;
@@ -119,43 +125,32 @@ export let Menu = class Menu extends LitElement {
119
125
  item.submenuCloseDelay = this.submenuCloseDelay;
120
126
  });
121
127
  }
122
- onSelectsChange() {
123
- if (!this.isSelectable && this.selectedKeys.length) {
124
- this.selectedKeys = [];
125
- this.onSelectedKeysChange();
126
- this.onValueChange();
128
+ async onSelectsChange() {
129
+ if (!this.isSelectable) {
130
+ // 不可选中,清空选中值
131
+ this.setSelectedKeys([]);
127
132
  }
128
- if (this.isSingle && this.selectedKeys.length > 1) {
129
- this.selectedKeys = this.selectedKeys.slice(0, 1);
130
- this.onSelectedKeysChange();
131
- this.onValueChange();
133
+ else if (this.isSingle) {
134
+ // 单选,只保留第一个选中的值
135
+ this.setSelectedKeys(this.selectedKeys.slice(0, 1));
132
136
  }
137
+ await this.onSelectedKeysChange();
133
138
  }
134
- onSelectedKeysChange(oldSelectedKeys) {
135
- // 根据 selectedKeys 读取出对应 menu-item 的 value。页面首次渲染时,values 始终为空数组
139
+ async onSelectedKeysChange() {
140
+ await this.definedController.whenDefined();
141
+ // 根据 selectedKeys 读取出对应 menu-item 的 value
136
142
  const values = this.itemsEnabled
137
143
  .filter((item) => this.selectedKeys.includes(item.key))
138
144
  .map((item) => item.value);
139
- // 如果是多选,且每一项值都不变,则视为未变更,不触发 change 事件
140
- if (this.isMultiple &&
141
- oldSelectedKeys &&
142
- oldSelectedKeys.length === this.selectedKeys.length &&
143
- oldSelectedKeys.every((v, i) => v === this.selectedKeys[i])) {
144
- this.hasSetDefaultValue = true;
145
- return;
146
- }
147
- this.value = this.isMultiple ? values : values[0] || undefined;
148
- if (this.hasSetDefaultValue) {
145
+ const value = this.isMultiple ? values : values[0] || undefined;
146
+ this.setValue(value);
147
+ if (!this.isInitial) {
149
148
  emit(this, 'change');
150
149
  }
151
- else {
152
- this.hasSetDefaultValue = true;
153
- }
154
150
  }
155
151
  async onValueChange() {
156
- if (!this.hasUpdated) {
157
- await this.updateComplete;
158
- }
152
+ this.isInitial = !this.hasUpdated;
153
+ await this.definedController.whenDefined();
159
154
  // 根据 value 找出对应的 menu-item,并把这些 menu-item 的 key 赋值给 selectedKeys
160
155
  if (!this.isSelectable) {
161
156
  this.updateSelected();
@@ -168,16 +163,16 @@ export let Menu = class Menu extends LitElement {
168
163
  ? [this.value]
169
164
  : this.value).filter((i) => i);
170
165
  if (!values.length) {
171
- this.selectedKeys = [];
166
+ this.setSelectedKeys([]);
172
167
  }
173
168
  else if (this.isSingle) {
174
169
  const firstItem = this.itemsEnabled.find((item) => item.value === values[0]);
175
- this.selectedKeys = firstItem ? [firstItem.key] : [];
170
+ this.setSelectedKeys(firstItem ? [firstItem.key] : []);
176
171
  }
177
172
  else if (this.isMultiple) {
178
- this.selectedKeys = this.itemsEnabled
173
+ this.setSelectedKeys(this.itemsEnabled
179
174
  .filter((item) => values.includes(item.value))
180
- .map((item) => item.key);
175
+ .map((item) => item.key));
181
176
  }
182
177
  this.updateSelected();
183
178
  this.updateFocusable();
@@ -200,8 +195,10 @@ export let Menu = class Menu extends LitElement {
200
195
  }
201
196
  firstUpdated(changedProperties) {
202
197
  super.firstUpdated(changedProperties);
203
- this.updateFocusable();
204
- this.lastActiveItem = this.items.find((item) => item.focusable);
198
+ this.definedController.whenDefined().then(() => {
199
+ this.updateFocusable();
200
+ this.lastActiveItem = this.items.find((item) => item.focusable);
201
+ });
205
202
  // 子菜单打开时,把焦点放到新的子菜单上
206
203
  this.addEventListener('submenu-open', (e) => {
207
204
  const $parentItem = $(e.target);
@@ -231,6 +228,19 @@ export let Menu = class Menu extends LitElement {
231
228
  render() {
232
229
  return html `<slot @slotchange="${this.onSlotChange}" @click="${this.onClick}" @keydown="${this.onKeyDown}"></slot>`;
233
230
  }
231
+ setSelectedKeys(selectedKeys) {
232
+ if (!arraysEqualIgnoreOrder(this.selectedKeys, selectedKeys)) {
233
+ this.selectedKeys = selectedKeys;
234
+ }
235
+ }
236
+ setValue(value) {
237
+ if (this.isSingle || isUndefined(this.value) || isUndefined(value)) {
238
+ this.value = value;
239
+ }
240
+ else if (!arraysEqualIgnoreOrder(this.value, value)) {
241
+ this.value = value;
242
+ }
243
+ }
234
244
  // 获取和指定菜单项同级的所有菜单项
235
245
  getSiblingsItems(item, onlyEnabled = false) {
236
246
  return $(item)
@@ -242,23 +252,29 @@ export let Menu = class Menu extends LitElement {
242
252
  updateFocusable() {
243
253
  // 焦点优先放在之前焦点所在的元素上
244
254
  if (this.lastActiveItem) {
245
- this.items.forEach((item) => (item.focusable = item.key === this.lastActiveItem.key));
255
+ this.items.forEach((item) => {
256
+ item.focusable = item.key === this.lastActiveItem.key;
257
+ });
246
258
  return;
247
259
  }
248
260
  // 没有选中任何一项,焦点放在第一个 menu-item 上
249
261
  if (!this.selectedKeys.length) {
250
- this.itemsEnabled.forEach((item, index) => (item.focusable = !index));
262
+ this.itemsEnabled.forEach((item, index) => {
263
+ item.focusable = !index;
264
+ });
251
265
  return;
252
266
  }
253
267
  // 如果是单选,焦点放在当前选中的元素上
254
268
  if (this.isSingle) {
255
- this.items.forEach((item) => (item.focusable = this.selectedKeys.includes(item.key)));
269
+ this.items.forEach((item) => {
270
+ item.focusable = this.selectedKeys.includes(item.key);
271
+ });
256
272
  return;
257
273
  }
258
274
  // 是多选,且原焦点不在 selectedKeys 上,焦点放在第一个选中的 menu-item 上
259
275
  if (this.isMultiple) {
260
276
  const focusableItem = this.items.find((item) => item.focusable);
261
- if (!(focusableItem === null || focusableItem === void 0 ? void 0 : focusableItem.key) ||
277
+ if (!focusableItem?.key ||
262
278
  !this.selectedKeys.includes(focusableItem.key)) {
263
279
  this.itemsEnabled
264
280
  .filter((item) => this.selectedKeys.includes(item.key))
@@ -268,7 +284,9 @@ export let Menu = class Menu extends LitElement {
268
284
  }
269
285
  updateSelected() {
270
286
  // 选中 menu-item
271
- this.items.forEach((item) => (item.selected = this.selectedKeys.includes(item.key)));
287
+ this.items.forEach((item) => {
288
+ item.selected = this.selectedKeys.includes(item.key);
289
+ });
272
290
  }
273
291
  // 切换一个菜单项的选中状态
274
292
  selectOne(item) {
@@ -281,28 +299,32 @@ export let Menu = class Menu extends LitElement {
281
299
  else {
282
300
  selectedKeys.push(item.key);
283
301
  }
284
- this.selectedKeys = selectedKeys;
302
+ this.setSelectedKeys(selectedKeys);
285
303
  }
286
304
  if (this.isSingle) {
287
305
  if (this.selectedKeys.includes(item.key)) {
288
- this.selectedKeys = [];
306
+ this.setSelectedKeys([]);
289
307
  }
290
308
  else {
291
- this.selectedKeys = [item.key];
309
+ this.setSelectedKeys([item.key]);
292
310
  }
293
311
  }
312
+ this.isInitial = false;
294
313
  this.updateSelected();
295
314
  }
296
315
  // 使一个 menu-item 可聚焦
297
- focusableOne(item) {
316
+ async focusableOne(item) {
298
317
  this.items.forEach((_item) => (_item.focusable = _item.key === item.key));
318
+ await delay(); // 等待 focusableMixin 更新完成
299
319
  }
300
320
  // 聚焦一个 menu-item
301
- async focusOne(item, options) {
302
- await delay(); // 等待 focusableMixin 更新完成
321
+ focusOne(item, options) {
303
322
  item.focus(options);
304
323
  }
305
- onClick(event) {
324
+ async onClick(event) {
325
+ if (!this.definedController.isDefined()) {
326
+ return;
327
+ }
306
328
  if (this.isSubmenu) {
307
329
  return;
308
330
  }
@@ -312,17 +334,20 @@ export let Menu = class Menu extends LitElement {
312
334
  }
313
335
  const target = event.target;
314
336
  const item = target.closest('mdui-menu-item');
315
- if (item === null || item === void 0 ? void 0 : item.disabled) {
337
+ if (item?.disabled) {
316
338
  return;
317
339
  }
318
340
  this.lastActiveItem = item;
319
341
  if (this.isSelectable && item.value) {
320
342
  this.selectOne(item);
321
343
  }
322
- this.focusableOne(item);
344
+ await this.focusableOne(item);
323
345
  this.focusOne(item);
324
346
  }
325
- onKeyDown(event) {
347
+ async onKeyDown(event) {
348
+ if (!this.definedController.isDefined()) {
349
+ return;
350
+ }
326
351
  if (this.isSubmenu) {
327
352
  return;
328
353
  }
@@ -337,7 +362,7 @@ export let Menu = class Menu extends LitElement {
337
362
  event.preventDefault();
338
363
  if (this.isSelectable && item.value) {
339
364
  this.selectOne(item);
340
- this.focusableOne(item);
365
+ await this.focusableOne(item);
341
366
  this.focusOne(item);
342
367
  }
343
368
  }
@@ -367,7 +392,7 @@ export let Menu = class Menu extends LitElement {
367
392
  index = 0;
368
393
  }
369
394
  this.lastActiveItem = items[index];
370
- this.focusableOne(items[index]);
395
+ await this.focusableOne(items[index]);
371
396
  this.focusOne(items[index]);
372
397
  return;
373
398
  }
@@ -412,7 +437,7 @@ __decorate([
412
437
  watch('submenuCloseDelay')
413
438
  ], Menu.prototype, "onSlotChange", null);
414
439
  __decorate([
415
- watch('selects')
440
+ watch('selects', true)
416
441
  ], Menu.prototype, "onSelectsChange", null);
417
442
  __decorate([
418
443
  watch('selectedKeys', true)
@@ -423,3 +448,4 @@ __decorate([
423
448
  Menu = __decorate([
424
449
  customElement('mdui-menu')
425
450
  ], Menu);
451
+ export { Menu };
@@ -1,2 +1,2 @@
1
1
  import { css } from 'lit';
2
- export const navigationBarItemStyle = css `:host{--shape-corner-indicator:var(--mdui-shape-corner-full);position:relative;z-index:0;flex:1;overflow:hidden;min-width:3rem;--mdui-comp-ripple-state-layer-color:var(--mdui-color-on-surface-variant)}.container{display:flex;flex-direction:column;align-items:center;justify-content:center;height:100%;text-decoration:none;cursor:pointer;-webkit-user-select:none;user-select:none;-webkit-tap-highlight-color:transparent;transition:padding var(--mdui-motion-duration-short4) var(--mdui-motion-easing-standard);padding-top:.75rem;padding-bottom:.75rem}mdui-ripple{z-index:1;left:50%;transform:translateX(-50%);transition:margin-top var(--mdui-motion-duration-short4) var(--mdui-motion-easing-standard);width:4rem;height:2rem;margin-top:.75rem;border-radius:var(--mdui-shape-corner-full)}.indicator{position:relative;display:flex;align-items:center;justify-content:center;background-color:transparent;border-radius:var(--shape-corner-indicator);transition:background-color var(--mdui-motion-duration-short1) var(--mdui-motion-easing-standard),width var(--mdui-motion-duration-short4) var(--mdui-motion-easing-standard);height:2rem;width:2rem}::slotted([slot=badge]){position:absolute;transform:translate(50%,-50%)}::slotted([slot=badge][variant=small]){transform:translate(.5625rem,-.5625rem)}.active-icon,.icon{color:rgb(var(--mdui-color-on-surface-variant));font-size:1.5rem}.active-icon mdui-icon,.icon mdui-icon,::slotted([slot=active]),::slotted([slot=icon]){font-size:inherit}.icon{display:flex}.active-icon{display:none}.label{display:flex;align-items:center;transition:opacity var(--mdui-motion-duration-short4) var(--mdui-motion-easing-linear);height:1rem;color:rgb(var(--mdui-color-on-surface-variant));margin-top:.25rem;margin-bottom:.25rem;font-size:var(--mdui-typescale-label-medium-size);font-weight:var(--mdui-typescale-label-medium-weight);letter-spacing:var(--mdui-typescale-label-medium-tracking);line-height:var(--mdui-typescale-label-medium-line-height)}:host([label-visibility=selected]:not([active])) mdui-ripple,:host([label-visibility=unlabeled]) mdui-ripple{margin-top:1.5rem}:host([label-visibility=selected]:not([active])) .container,:host([label-visibility=unlabeled]) .container{padding-top:1.5rem;padding-bottom:0}:host([label-visibility=selected]:not([active])) .label,:host([label-visibility=unlabeled]) .label{opacity:0}:host([active]){--mdui-comp-ripple-state-layer-color:var(--mdui-color-on-surface)}:host([active]) .indicator{width:4rem;background-color:rgb(var(--mdui-color-secondary-container))}:host([active]) .active-icon,:host([active]) .icon{color:rgb(var(--mdui-color-on-secondary-container))}:host([active]) .has-active-icon .active-icon{display:flex}:host([active]) .has-active-icon .icon{display:none}:host([active]) .label{color:rgb(var(--mdui-color-on-surface))}`;
2
+ export const navigationBarItemStyle = css `:host{--shape-corner-indicator:var(--mdui-shape-corner-full);position:relative;z-index:0;flex:1;overflow:hidden;min-width:3rem;--mdui-comp-ripple-state-layer-color:var(--mdui-color-on-surface-variant)}.container{display:flex;flex-direction:column;align-items:center;justify-content:center;height:100%;text-decoration:none;cursor:pointer;-webkit-user-select:none;user-select:none;-webkit-tap-highlight-color:transparent;padding-top:.75rem;padding-bottom:.75rem}.container:not(.initial){transition:padding var(--mdui-motion-duration-short4) var(--mdui-motion-easing-standard)}mdui-ripple{z-index:1;left:50%;transform:translateX(-50%);width:4rem;height:2rem;margin-top:.75rem;border-radius:var(--mdui-shape-corner-full)}mdui-ripple:not(.initial){transition:margin-top var(--mdui-motion-duration-short4) var(--mdui-motion-easing-standard)}.indicator{position:relative;display:flex;align-items:center;justify-content:center;background-color:transparent;border-radius:var(--shape-corner-indicator);height:2rem;width:2rem}:not(.initial) .indicator{transition:background-color var(--mdui-motion-duration-short1) var(--mdui-motion-easing-standard),width var(--mdui-motion-duration-short4) var(--mdui-motion-easing-standard)}::slotted([slot=badge]){position:absolute;transform:translate(50%,-50%)}::slotted([slot=badge][variant=small]){transform:translate(.5625rem,-.5625rem)}.active-icon,.icon{color:rgb(var(--mdui-color-on-surface-variant));font-size:1.5rem}.active-icon mdui-icon,.icon mdui-icon,::slotted([slot=active]),::slotted([slot=icon]){font-size:inherit}.icon{display:flex}.active-icon{display:none}.label{display:flex;align-items:center;height:1rem;color:rgb(var(--mdui-color-on-surface-variant));margin-top:.25rem;margin-bottom:.25rem;font-size:var(--mdui-typescale-label-medium-size);font-weight:var(--mdui-typescale-label-medium-weight);letter-spacing:var(--mdui-typescale-label-medium-tracking);line-height:var(--mdui-typescale-label-medium-line-height)}:not(.initial) .label{transition:opacity var(--mdui-motion-duration-short4) var(--mdui-motion-easing-linear)}:host(:not([active])) mdui-ripple.label-visibility-selected,mdui-ripple.label-visibility-unlabeled{margin-top:1.5rem}.container.label-visibility-unlabeled,:host(:not([active])) .container.label-visibility-selected{padding-top:1.5rem;padding-bottom:0}.container.label-visibility-unlabeled .label,:host(:not([active])) .container.label-visibility-selected .label{opacity:0}:host([active]){--mdui-comp-ripple-state-layer-color:var(--mdui-color-on-surface)}:host([active]) .indicator{width:4rem;background-color:rgb(var(--mdui-color-secondary-container))}:host([active]) .active-icon,:host([active]) .icon{color:rgb(var(--mdui-color-on-secondary-container))}:host([active]) .has-active-icon .active-icon{display:flex}:host([active]) .has-active-icon .icon{display:none}:host([active]) .label{color:rgb(var(--mdui-color-on-surface))}`;
@@ -46,11 +46,15 @@ export declare class NavigationBarItem extends NavigationBarItem_base {
46
46
  */
47
47
  value?: string;
48
48
  /**
49
- * 文本的可视状态,由 `navigation-bar` 调用
49
+ * 文本的可视状态,由 `<mdui-navigation-bar>` 组件控制该参数
50
50
  */
51
51
  protected labelVisibility?: 'selected' | 'labeled' | 'unlabeled';
52
52
  /**
53
- * 是否为激活状态,由 `navigation-bar` 组件控制该参数
53
+ * 是否是初始状态,不显示动画。由 `<mdui-navigation-bar>` 组件控制该参数
54
+ */
55
+ protected isInitial: boolean;
56
+ /**
57
+ * 是否为激活状态,由 `<mdui-navigation-bar>` 组件控制该参数
54
58
  */
55
59
  protected active: boolean;
56
60
  private disabled;
@@ -41,16 +41,20 @@ import { navigationBarItemStyle } from './navigation-bar-item-style.js';
41
41
  *
42
42
  * @cssprop --shape-corner-indicator - 指示器的圆角大小。可以指定一个具体的像素值;但更推荐[引用设计令牌](/docs/2/styles/design-tokens#shape-corner)
43
43
  */
44
- export let NavigationBarItem = class NavigationBarItem extends AnchorMixin(RippleMixin(FocusableMixin(LitElement))) {
44
+ let NavigationBarItem = class NavigationBarItem extends AnchorMixin(RippleMixin(FocusableMixin(LitElement))) {
45
45
  constructor() {
46
46
  super(...arguments);
47
47
  /**
48
- * 是否为激活状态,由 `navigation-bar` 组件控制该参数
48
+ * 是否是初始状态,不显示动画。由 `<mdui-navigation-bar>` 组件控制该参数
49
+ */
50
+ this.isInitial = true;
51
+ /**
52
+ * 是否为激活状态,由 `<mdui-navigation-bar>` 组件控制该参数
49
53
  */
50
54
  this.active = false;
51
55
  // 是否禁用该元素,该组件没有禁用状态
52
56
  this.disabled = false;
53
- // 每一个 `navigation-bar-item` 元素都添加一个唯一的 key
57
+ // 每一个 `<navigation-bar-item>` 元素都添加一个唯一的 key
54
58
  this.key = uniqueId();
55
59
  this.rippleRef = createRef();
56
60
  this.hasSlotController = new HasSlotController(this, 'active-icon');
@@ -62,18 +66,26 @@ export let NavigationBarItem = class NavigationBarItem extends AnchorMixin(Rippl
62
66
  return this.disabled;
63
67
  }
64
68
  get focusElement() {
65
- var _a;
66
- return this.href ? (_a = this.renderRoot) === null || _a === void 0 ? void 0 : _a.querySelector('._a') : this;
69
+ return this.href ? this.renderRoot?.querySelector('._a') : this;
67
70
  }
68
71
  get focusDisabled() {
69
72
  return this.disabled;
70
73
  }
71
74
  render() {
72
- const className = cc({
73
- container: true,
74
- 'has-active-icon': this.activeIcon || this.hasSlotController.test('active-icon'),
75
+ const labelVisibilityClassName = cc({
76
+ 'label-visibility-selected': this.labelVisibility === 'selected',
77
+ 'label-visibility-labeled': this.labelVisibility === 'labeled',
78
+ 'label-visibility-unlabeled': this.labelVisibility === 'unlabeled',
79
+ initial: this.isInitial,
75
80
  });
76
- return html `<mdui-ripple .noRipple="${!this.active || this.noRipple}" ${ref(this.rippleRef)}></mdui-ripple>${this.href
81
+ const className = cc([
82
+ {
83
+ container: true,
84
+ 'has-active-icon': this.activeIcon || this.hasSlotController.test('active-icon'),
85
+ },
86
+ labelVisibilityClassName,
87
+ ]);
88
+ return html `<mdui-ripple .noRipple="${!this.active || this.noRipple}" class="${labelVisibilityClassName}" ${ref(this.rippleRef)}></mdui-ripple>${this.href
77
89
  ? this.renderAnchor({
78
90
  part: 'container',
79
91
  className,
@@ -103,8 +115,11 @@ __decorate([
103
115
  property({ reflect: true })
104
116
  ], NavigationBarItem.prototype, "value", void 0);
105
117
  __decorate([
106
- property({ reflect: true, attribute: 'label-visibility' })
118
+ state()
107
119
  ], NavigationBarItem.prototype, "labelVisibility", void 0);
120
+ __decorate([
121
+ state()
122
+ ], NavigationBarItem.prototype, "isInitial", void 0);
108
123
  __decorate([
109
124
  property({
110
125
  type: Boolean,
@@ -118,3 +133,4 @@ __decorate([
118
133
  NavigationBarItem = __decorate([
119
134
  customElement('mdui-navigation-bar-item')
120
135
  ], NavigationBarItem);
136
+ export { NavigationBarItem };
@@ -1,5 +1,4 @@
1
- import '@mdui/jq/methods/find.js';
2
- import '@mdui/jq/methods/get.js';
1
+ import { PropertyValues } from 'lit';
3
2
  import { LayoutItemBase } from '../layout/layout-item-base.js';
4
3
  import type { LayoutPlacement } from '../layout/helper.js';
5
4
  import type { ScrollPaddingPosition } from '@mdui/shared/mixins/scrollBehavior.js';
@@ -52,14 +51,15 @@ export declare class NavigationBar extends NavigationBar_base {
52
51
  */
53
52
  scrollBehavior?: 'hide';
54
53
  private activeKey;
55
- private hasSetDefaultValue;
54
+ private readonly items;
55
+ private isInitial;
56
+ private definedController;
56
57
  protected get scrollPaddingPosition(): ScrollPaddingPosition;
57
58
  protected get layoutPlacement(): LayoutPlacement;
58
- private get items();
59
59
  private onActiveKeyChange;
60
60
  private onValueChange;
61
61
  private onLabelVisibilityChange;
62
- connectedCallback(): void;
62
+ protected firstUpdated(_changedProperties: PropertyValues): void;
63
63
  protected render(): TemplateResult;
64
64
  /**
65
65
  * 滚动行为
@@ -67,7 +67,7 @@ export declare class NavigationBar extends NavigationBar_base {
67
67
  */
68
68
  protected runScrollThreshold(isScrollingUp: boolean): void;
69
69
  private onClick;
70
- private updateActive;
70
+ private updateItems;
71
71
  private onSlotChange;
72
72
  }
73
73
  declare global {
@@ -1,9 +1,7 @@
1
1
  import { __decorate } from "tslib";
2
2
  import { html } from 'lit';
3
- import { customElement, property, state } from 'lit/decorators.js';
4
- import { $ } from '@mdui/jq/$.js';
5
- import '@mdui/jq/methods/find.js';
6
- import '@mdui/jq/methods/get.js';
3
+ import { customElement, property, queryAssignedElements, state, } from 'lit/decorators.js';
4
+ import { DefinedController } from '@mdui/shared/controllers/defined.js';
7
5
  import { watch } from '@mdui/shared/decorators/watch.js';
8
6
  import { booleanConverter } from '@mdui/shared/helpers/decorator.js';
9
7
  import { emit } from '@mdui/shared/helpers/event.js';
@@ -33,7 +31,7 @@ import { navigationBarStyle } from './navigation-bar-style.js';
33
31
  * @cssprop --shape-corner - 组件的圆角大小。可以指定一个具体的像素值;但更推荐[引用设计令牌](/docs/2/styles/design-tokens#shape-corner)
34
32
  * @cssprop --z-index - 组件的 CSS 的 `z-index` 值
35
33
  */
36
- export let NavigationBar = class NavigationBar extends ScrollBehaviorMixin(LayoutItemBase) {
34
+ let NavigationBar = class NavigationBar extends ScrollBehaviorMixin(LayoutItemBase) {
37
35
  constructor() {
38
36
  super(...arguments);
39
37
  /**
@@ -51,8 +49,11 @@ export let NavigationBar = class NavigationBar extends ScrollBehaviorMixin(Layou
51
49
  this.labelVisibility = 'auto';
52
50
  // 因为 navigation-bar-item 的 value 可能会重复,所以在每个 navigation-bar-item 元素上都添加了一个唯一的 key,通过 activeKey 来记录激活状态的 key
53
51
  this.activeKey = 0;
54
- // 是否已完成初始 value 的设置。首次设置初始值时,不触发 change 事件
55
- this.hasSetDefaultValue = false;
52
+ // 是否是初始状态,初始状态不触发 change 事件,没有动画
53
+ this.isInitial = true;
54
+ this.definedController = new DefinedController(this, {
55
+ relatedElements: ['mdui-navigation-bar-item'],
56
+ });
56
57
  }
57
58
  get scrollPaddingPosition() {
58
59
  return 'bottom';
@@ -60,43 +61,28 @@ export let NavigationBar = class NavigationBar extends ScrollBehaviorMixin(Layou
60
61
  get layoutPlacement() {
61
62
  return 'bottom';
62
63
  }
63
- // 所有的子项元素
64
- get items() {
65
- return $(this)
66
- .find('mdui-navigation-bar-item')
67
- .get();
68
- }
69
- onActiveKeyChange() {
64
+ async onActiveKeyChange() {
65
+ await this.definedController.whenDefined();
70
66
  // 根据 activeKey 读取对应 navigation-bar-item 的值
71
67
  const item = this.items.find((item) => item.key === this.activeKey);
72
- this.value = item === null || item === void 0 ? void 0 : item.value;
73
- if (this.hasSetDefaultValue) {
68
+ this.value = item?.value;
69
+ if (!this.isInitial) {
74
70
  emit(this, 'change');
75
71
  }
76
- else {
77
- this.hasSetDefaultValue = true;
78
- }
79
72
  }
80
- onValueChange() {
81
- var _a;
73
+ async onValueChange() {
74
+ this.isInitial = !this.hasUpdated;
75
+ await this.definedController.whenDefined();
82
76
  const item = this.items.find((item) => item.value === this.value);
83
- this.activeKey = (_a = item === null || item === void 0 ? void 0 : item.key) !== null && _a !== void 0 ? _a : 0;
84
- this.updateActive();
77
+ this.activeKey = item?.key ?? 0;
78
+ this.updateItems();
85
79
  }
86
- onLabelVisibilityChange() {
87
- const items = this.items;
88
- // 为 navigation-bar-item 设置 labelVisibility 属性
89
- const labelVisibility = this.labelVisibility === 'auto'
90
- ? items.length <= 3
91
- ? 'labeled'
92
- : 'selected'
93
- : this.labelVisibility;
94
- items.forEach((item) => {
95
- item.labelVisibility = labelVisibility;
96
- });
80
+ async onLabelVisibilityChange() {
81
+ await this.definedController.whenDefined();
82
+ this.updateItems();
97
83
  }
98
- connectedCallback() {
99
- super.connectedCallback();
84
+ firstUpdated(_changedProperties) {
85
+ super.firstUpdated(_changedProperties);
100
86
  this.addEventListener('transitionend', (event) => {
101
87
  if (event.target === this) {
102
88
  emit(this, this.hide ? 'hidden' : 'shown');
@@ -134,13 +120,27 @@ export let NavigationBar = class NavigationBar extends ScrollBehaviorMixin(Layou
134
120
  const target = event.target;
135
121
  const item = target.closest('mdui-navigation-bar-item');
136
122
  this.activeKey = item.key;
137
- this.updateActive();
123
+ this.isInitial = false;
124
+ this.updateItems();
138
125
  }
139
- updateActive() {
140
- this.items.forEach((item) => (item.active = this.activeKey === item.key));
126
+ // 更新 <mdui-navigation-bar-item> 的状态
127
+ updateItems() {
128
+ const items = this.items;
129
+ // <mdui-navigation-bar-item> 的 labelVisibility 不含 auto
130
+ const labelVisibility = this.labelVisibility === 'auto'
131
+ ? items.length <= 3
132
+ ? 'labeled'
133
+ : 'selected'
134
+ : this.labelVisibility;
135
+ items.forEach((item) => {
136
+ item.active = this.activeKey === item.key;
137
+ item.labelVisibility = labelVisibility;
138
+ item.isInitial = this.isInitial;
139
+ });
141
140
  }
142
- onSlotChange() {
143
- this.onLabelVisibilityChange();
141
+ async onSlotChange() {
142
+ await this.definedController.whenDefined();
143
+ this.updateItems();
144
144
  }
145
145
  };
146
146
  NavigationBar.styles = [
@@ -167,7 +167,13 @@ __decorate([
167
167
  state()
168
168
  ], NavigationBar.prototype, "activeKey", void 0);
169
169
  __decorate([
170
- watch('activeKey')
170
+ queryAssignedElements({
171
+ selector: 'mdui-navigation-bar-item',
172
+ flatten: true,
173
+ })
174
+ ], NavigationBar.prototype, "items", void 0);
175
+ __decorate([
176
+ watch('activeKey', true)
171
177
  ], NavigationBar.prototype, "onActiveKeyChange", null);
172
178
  __decorate([
173
179
  watch('value')
@@ -178,3 +184,4 @@ __decorate([
178
184
  NavigationBar = __decorate([
179
185
  customElement('mdui-navigation-bar')
180
186
  ], NavigationBar);
187
+ export { NavigationBar };
@@ -2,7 +2,7 @@ import '@mdui/jq/methods/css.js';
2
2
  import '@mdui/jq/methods/innerWidth.js';
3
3
  import { LayoutItemBase } from '../layout/layout-item-base.js';
4
4
  import type { LayoutPlacement } from '../layout/helper.js';
5
- import type { CSSResultGroup, TemplateResult } from 'lit';
5
+ import type { CSSResultGroup, PropertyValues, TemplateResult } from 'lit';
6
6
  /**
7
7
  * 在手机端,`modal` 始终为 `true`;大于手机端时,`modal` 属性才开始生效
8
8
  *
@@ -66,16 +66,20 @@ export declare class NavigationDrawer extends LayoutItemBase {
66
66
  private modalHelper;
67
67
  private readonly overlayRef;
68
68
  private readonly panelRef;
69
+ private readonly definedController;
69
70
  protected get layoutPlacement(): LayoutPlacement;
70
71
  private get lockTarget();
71
72
  private get isModal();
72
73
  private onContainedChange;
73
74
  private onPlacementChange;
75
+ private onMobileChange;
74
76
  private onOpenChange;
75
77
  connectedCallback(): void;
76
78
  disconnectedCallback(): void;
79
+ protected firstUpdated(_changedProperties: PropertyValues): void;
77
80
  protected render(): TemplateResult;
78
81
  private onOverlayClick;
82
+ private getLockTargetAnimate;
79
83
  }
80
84
  declare global {
81
85
  interface HTMLElementTagNameMap {