vueless 1.4.12-beta.15 → 1.4.12-beta.16

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vueless",
3
- "version": "1.4.12-beta.15",
3
+ "version": "1.4.12-beta.16",
4
4
  "description": "Vue Styleless UI Component Library, powered by Tailwind CSS.",
5
5
  "author": "Johnny Grid <hello@vueless.com> (https://vueless.com)",
6
6
  "homepage": "https://vueless.com",
@@ -119,6 +119,16 @@ function deactivate() {
119
119
  customView.value = View.Day;
120
120
  }
121
121
 
122
+ function deactivateOnBlur(event: FocusEvent) {
123
+ const related = event.relatedTarget as HTMLElement | null;
124
+
125
+ if (related && wrapperRef.value?.contains(related)) {
126
+ return;
127
+ }
128
+
129
+ deactivate();
130
+ }
131
+
122
132
  function onUserFormatDateChange(value: string) {
123
133
  userFormatDate.value = value.trim();
124
134
  }
@@ -279,7 +289,7 @@ watchEffect(() => {
279
289
  </script>
280
290
 
281
291
  <template>
282
- <div v-bind="wrapperAttrs" ref="wrapper" :data-test="getDataTest()">
292
+ <div v-bind="wrapperAttrs" ref="wrapper" :data-test="getDataTest()" @focusout="deactivateOnBlur">
283
293
  <UInput
284
294
  :id="elementId"
285
295
  :key="String(userFormatDate)"
@@ -356,6 +356,53 @@ describe("UDatePicker.vue", () => {
356
356
  expect(calendar.isVisible()).toBe(true);
357
357
  });
358
358
 
359
+ it("Calendar – hides when focus leaves the whole component", async () => {
360
+ const component = mount(UDatePicker, {
361
+ props: {
362
+ modelValue: new Date(),
363
+ },
364
+ attachTo: document.body,
365
+ });
366
+
367
+ const input = component.getComponent(UInput).find("input");
368
+ const calendar = component.findComponent({ name: "UCalendar" });
369
+
370
+ await input.trigger("focus");
371
+ expect(calendar.isVisible()).toBe(true);
372
+
373
+ const outsideElement = document.createElement("button");
374
+
375
+ document.body.appendChild(outsideElement);
376
+
377
+ await component.trigger("focusout", { relatedTarget: outsideElement });
378
+
379
+ expect(calendar.isVisible()).toBe(false);
380
+
381
+ outsideElement.remove();
382
+ component.unmount();
383
+ });
384
+
385
+ it("Calendar – stays open when focus moves inside the component", async () => {
386
+ const component = mount(UDatePicker, {
387
+ props: {
388
+ modelValue: new Date(),
389
+ },
390
+ attachTo: document.body,
391
+ });
392
+
393
+ const input = component.getComponent(UInput).find("input");
394
+ const calendar = component.findComponent({ name: "UCalendar" });
395
+
396
+ await input.trigger("focus");
397
+ expect(calendar.isVisible()).toBe(true);
398
+
399
+ await component.trigger("focusout", { relatedTarget: calendar.element });
400
+
401
+ expect(calendar.isVisible()).toBe(true);
402
+
403
+ component.unmount();
404
+ });
405
+
359
406
  it("Calendar – hides when escape key is pressed on calendar", async () => {
360
407
  const component = mount(UDatePicker, {
361
408
  props: {
@@ -580,6 +580,7 @@ const {
580
580
  <UButton
581
581
  round
582
582
  square
583
+ tabindex="-1"
583
584
  v-bind="addOptionButtonAttrs"
584
585
  :data-test="getDataTest('add-button')"
585
586
  @click="onClickAddOption"
@@ -556,7 +556,7 @@ const {
556
556
 
557
557
  <div
558
558
  ref="wrapper"
559
- :tabindex="searchable || disabled ? -1 : 0"
559
+ :tabindex="disabled ? -1 : searchable && isOpen ? -1 : 0"
560
560
  role="combobox"
561
561
  :aria-expanded="ariaExpanded"
562
562
  aria-haspopup="listbox"
@@ -255,6 +255,63 @@ describe("USelect.vue", () => {
255
255
  expect(component.getComponent(UListbox).props("searchable")).toBe(true);
256
256
  });
257
257
 
258
+ it("Searchable – closes when the search input blurs to an outside element", async () => {
259
+ const component = mount(USelect, {
260
+ props: {
261
+ searchable: true,
262
+ options: defaultOptions,
263
+ },
264
+ attachTo: document.body,
265
+ });
266
+
267
+ await component.get("[role='combobox']").trigger("focus");
268
+ await flushPromises();
269
+
270
+ expect(component.emitted("open")).toBeTruthy();
271
+
272
+ const outside = document.createElement("button");
273
+
274
+ document.body.appendChild(outside);
275
+
276
+ await component
277
+ .getComponent(UListbox)
278
+ .get("input")
279
+ .trigger("blur", { relatedTarget: outside });
280
+ await flushPromises();
281
+
282
+ expect(component.emitted("close")).toBeTruthy();
283
+ expect(component.findComponent(UListbox).exists()).toBe(false);
284
+
285
+ outside.remove();
286
+ component.unmount();
287
+ });
288
+
289
+ it("Searchable – stays open when focus moves within its own listbox", async () => {
290
+ const component = mount(USelect, {
291
+ props: {
292
+ searchable: true,
293
+ options: defaultOptions,
294
+ },
295
+ attachTo: document.body,
296
+ });
297
+
298
+ await component.get("[role='combobox']").trigger("focus");
299
+ await flushPromises();
300
+
301
+ const listboxEl = component.getComponent(UListbox).element as HTMLElement;
302
+
303
+ await component
304
+ .getComponent(UListbox)
305
+ .get("input")
306
+ .trigger("blur", { relatedTarget: listboxEl });
307
+ await flushPromises();
308
+
309
+ expect(component.emitted("close")).toBeFalsy();
310
+ expect(component.findComponent(UListbox).exists()).toBe(true);
311
+
312
+ component.unmount();
313
+ });
314
+
258
315
  it("Search v-model – passes search to UListbox and filters", async () => {
259
316
  const component = mount(USelect, {
260
317
  props: {