@crowdstrike/glide-core 0.30.1 → 0.31.0

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 (2) hide show
  1. package/dist/menu.js +15 -53
  2. package/package.json +1 -1
package/dist/menu.js CHANGED
@@ -54,7 +54,7 @@ let Menu = class Menu extends LitElement {
54
54
  // `#onComponentFocusOut()` to decide if Menu should close. Also used in
55
55
  // `#onTargetAndDefaultSlotKeyDown()` to decide if we need to move focus.
56
56
  this.#hasVoiceOverMovedFocusToOptionsOrAnOption = false;
57
- // Set in `#onTargetSlotMouseUp()`. Used in `#onDocumentClick()` to guard against
57
+ // Set in `#onDefaultSlotMouseUp()`. Used in `#onDocumentClick()` to guard against
58
58
  // Menu closing when any number of things that are not an Option are clicked. Those
59
59
  // "click" events will be retargeted to Menu's host the moment they bubble out of
60
60
  // Menu. So checking in `#onDocumentClick()` if the click's `event.target` came
@@ -67,8 +67,8 @@ let Menu = class Menu extends LitElement {
67
67
  // used in `connectedCallback()` to guard against listening for document clicks for
68
68
  // sub-Menus.
69
69
  this.#isSubMenuOpen = false;
70
- // Set in `#onTargetSlotMouseUp()` and `#onDocumentClick()`. Used in
71
- // `#onDocumentClick()`:
70
+ // Similar situation as with `isDefaultSlotClick`. Set in `#onTargetSlotClick()`
71
+ // and `#onDocumentClick()`. Used in `#onDocumentClick()`:
72
72
  //
73
73
  // 1. Menu is open.
74
74
  // 2. User clicks Menu's target.
@@ -76,19 +76,9 @@ let Menu = class Menu extends LitElement {
76
76
  // 4. `#onTargetSlotClick()` sets `open` to true`.
77
77
  // 5. Menu never closes.
78
78
  //
79
- // Setting `#isTargetSlotMouseUp` to `true` in `#onTargetSlotMouseUp()` gives
79
+ // Setting `#isTargetSlotClick` to `true` in `#onTargetSlotClick()` gives
80
80
  // `#onDocumentClick()` the information it needs to not set `open` to `false`.
81
- //
82
- // The normal approach would be to set an `#isTargetSlotClick` property in
83
- // `#onTargetSlotClick()`. But `#onDocumentClick()` listens for "click" events in
84
- // their capture phase. So `#onDocumentClick()` would be called before
85
- // `#onTargetSlotClick()`.
86
- //
87
- // Note too that `#onDocumentClick()` sets `#isTargetSlotMouseUp` to `false`
88
- // instead of `#onTargetSlotClick()` doing it. That's so `#isTargetSlotMouseUp`
89
- // is set to `false` even if the user mouses down on Menu's target then moves the
90
- // mouse outside of Menu before mousing up.
91
- this.#isTargetSlotMouseUp = false;
81
+ this.#isTargetSlotClick = false;
92
82
  this.#localize = new LocalizeController(this);
93
83
  this.#targetSlotElementRef = createRef();
94
84
  // An arrow function field instead of a method so `this` is closed over and set to
@@ -98,8 +88,8 @@ let Menu = class Menu extends LitElement {
98
88
  this.#isDefaultSlotClick = false;
99
89
  return;
100
90
  }
101
- if (this.#isTargetSlotMouseUp) {
102
- this.#isTargetSlotMouseUp = false;
91
+ if (this.#isTargetSlotClick) {
92
+ this.#isTargetSlotClick = false;
103
93
  return;
104
94
  }
105
95
  if (this.#optionsElement) {
@@ -175,20 +165,7 @@ let Menu = class Menu extends LitElement {
175
165
  // easier to understand because developers don't have to think about sub-Menus when
176
166
  // looking at `#onDocumentClick()`.
177
167
  if (!this.#isSubMenu) {
178
- // 1. The consumer has a "click" handler on an element that isn't Menu's target.
179
- // 2. The user clicks that element.
180
- // 3. The handler is called. It sets `open` to `true`.
181
- // 4. The "click" bubbles up and is handled by `#onDocumentClick()`.
182
- // 5. `#onDocumentClick()` sets `open` to `false` because the click came from
183
- // outside Menu.
184
- // 6. Menu is opened then immediately closed and so never opens.
185
- //
186
- // `capture` ensures `#onDocumentClick()` is called before #3, so that `open` set
187
- // `true` in the consumer's handler isn't overwritten by `#onDocumentClick()`
188
- // handler setting it to `false`.
189
- document.addEventListener('click', this.#onDocumentClick, {
190
- capture: true,
191
- });
168
+ document.addEventListener('click', this.#onDocumentClick);
192
169
  }
193
170
  }
194
171
  createRenderRoot() {
@@ -197,9 +174,7 @@ let Menu = class Menu extends LitElement {
197
174
  }
198
175
  disconnectedCallback() {
199
176
  super.disconnectedCallback();
200
- document.removeEventListener('click', this.#onDocumentClick, {
201
- capture: true,
202
- });
177
+ document.removeEventListener('click', this.#onDocumentClick);
203
178
  }
204
179
  firstUpdated() {
205
180
  if (this.#optionsElement && this.#targetElement) {
@@ -293,7 +268,6 @@ let Menu = class Menu extends LitElement {
293
268
  name="target"
294
269
  @click=${this.#onTargetSlotClick}
295
270
  @keydown=${this.#onTargetAndDefaultSlotKeyDown}
296
- @mouseup=${this.#onTargetSlotMouseUp}
297
271
  @input=${this.#onTargetSlotInput}
298
272
  @slotchange=${this.#onTargetSlotChange}
299
273
  ${assertSlot([Element])}
@@ -341,7 +315,7 @@ let Menu = class Menu extends LitElement {
341
315
  // `#onComponentFocusOut()` to decide if Menu should close. Also used in
342
316
  // `#onTargetAndDefaultSlotKeyDown()` to decide if we need to move focus.
343
317
  #hasVoiceOverMovedFocusToOptionsOrAnOption;
344
- // Set in `#onTargetSlotMouseUp()`. Used in `#onDocumentClick()` to guard against
318
+ // Set in `#onDefaultSlotMouseUp()`. Used in `#onDocumentClick()` to guard against
345
319
  // Menu closing when any number of things that are not an Option are clicked. Those
346
320
  // "click" events will be retargeted to Menu's host the moment they bubble out of
347
321
  // Menu. So checking in `#onDocumentClick()` if the click's `event.target` came
@@ -354,8 +328,8 @@ let Menu = class Menu extends LitElement {
354
328
  // used in `connectedCallback()` to guard against listening for document clicks for
355
329
  // sub-Menus.
356
330
  #isSubMenuOpen;
357
- // Set in `#onTargetSlotMouseUp()` and `#onDocumentClick()`. Used in
358
- // `#onDocumentClick()`:
331
+ // Similar situation as with `isDefaultSlotClick`. Set in `#onTargetSlotClick()`
332
+ // and `#onDocumentClick()`. Used in `#onDocumentClick()`:
359
333
  //
360
334
  // 1. Menu is open.
361
335
  // 2. User clicks Menu's target.
@@ -363,19 +337,9 @@ let Menu = class Menu extends LitElement {
363
337
  // 4. `#onTargetSlotClick()` sets `open` to true`.
364
338
  // 5. Menu never closes.
365
339
  //
366
- // Setting `#isTargetSlotMouseUp` to `true` in `#onTargetSlotMouseUp()` gives
340
+ // Setting `#isTargetSlotClick` to `true` in `#onTargetSlotClick()` gives
367
341
  // `#onDocumentClick()` the information it needs to not set `open` to `false`.
368
- //
369
- // The normal approach would be to set an `#isTargetSlotClick` property in
370
- // `#onTargetSlotClick()`. But `#onDocumentClick()` listens for "click" events in
371
- // their capture phase. So `#onDocumentClick()` would be called before
372
- // `#onTargetSlotClick()`.
373
- //
374
- // Note too that `#onDocumentClick()` sets `#isTargetSlotMouseUp` to `false`
375
- // instead of `#onTargetSlotClick()` doing it. That's so `#isTargetSlotMouseUp`
376
- // is set to `false` even if the user mouses down on Menu's target then moves the
377
- // mouse outside of Menu before mousing up.
378
- #isTargetSlotMouseUp;
342
+ #isTargetSlotClick;
379
343
  #localize;
380
344
  #offset;
381
345
  // Used in various situations to reactivate the previously active Option.
@@ -1117,6 +1081,7 @@ let Menu = class Menu extends LitElement {
1117
1081
  }
1118
1082
  }
1119
1083
  #onTargetSlotClick(event) {
1084
+ this.#isTargetSlotClick = true;
1120
1085
  const closestOption = event.target instanceof Element &&
1121
1086
  event.target.closest('glide-core-option');
1122
1087
  const isSubMenuTarget = event.target instanceof Element && Boolean(closestOption);
@@ -1179,9 +1144,6 @@ let Menu = class Menu extends LitElement {
1179
1144
  #onTargetSlotInput() {
1180
1145
  this.open = true;
1181
1146
  }
1182
- #onTargetSlotMouseUp() {
1183
- this.#isTargetSlotMouseUp = true;
1184
- }
1185
1147
  #show() {
1186
1148
  this.#cleanUpFloatingUi?.();
1187
1149
  if (this.#previouslyActiveOption &&
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crowdstrike/glide-core",
3
- "version": "0.30.1",
3
+ "version": "0.31.0",
4
4
  "description": "A Web Component design system",
5
5
  "author": "CrowdStrike UX Team",
6
6
  "license": "Apache-2.0",