@vaadin/vaadin-select 2.4.1 → 2.4.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/README.md CHANGED
@@ -1,21 +1,18 @@
1
- [![npm version](https://badgen.net/npm/v/@vaadin/vaadin-select)](https://www.npmjs.com/package/@vaadin/vaadin-select)
2
- [![Bower version](https://badgen.net/github/release/vaadin/vaadin-select)](https://github.com/vaadin/vaadin-select/releases)
3
- [![Published on webcomponents.org](https://img.shields.io/badge/webcomponents.org-published-blue.svg)](https://www.webcomponents.org/element/vaadin/vaadin-select)
4
- [![Build Status](https://travis-ci.org/vaadin/vaadin-select.svg?branch=master)](https://travis-ci.org/vaadin/vaadin-select)
5
- [![Coverage Status](https://coveralls.io/repos/github/vaadin/vaadin-select/badge.svg?branch=master)](https://coveralls.io/github/vaadin/vaadin-select?branch=master)
6
- [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/vaadin/web-components?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
1
+ # <vaadin-select>
7
2
 
8
- [![Published on Vaadin Directory](https://img.shields.io/badge/Vaadin%20Directory-published-00b4f0.svg)](https://vaadin.com/directory/component/vaadinvaadin-select)
9
- [![Stars on vaadin.com/directory](https://img.shields.io/vaadin-directory/star/vaadinvaadin-select.svg)](https://vaadin.com/directory/component/vaadinvaadin-select)
3
+ > ⚠️ Starting from Vaadin 20, the source code and issues for this component are migrated to the [`vaadin/web-components`](https://github.com/vaadin/web-components/tree/master/packages/vaadin-select) monorepository.
4
+ > This repository contains the source code and releases of `<vaadin-select>` for the Vaadin versions 10 to 19.
10
5
 
11
- # &lt;vaadin-select&gt;
6
+ [&lt;vaadin-select&gt;](https://vaadin.com/components/vaadin-select) is a Web Component similar to a native browser select element, part of the [Vaadin components](https://vaadin.com/components).
12
7
 
13
- [Live Demo ↗](https://cdn.vaadin.com/vaadin-select/2.0.0-beta1/demo)
8
+ [Live Demo ↗](https://vaadin.com/components/vaadin-select/html-examples)
14
9
  |
15
- [API documentation ↗](https://cdn.vaadin.com/vaadin-select/2.0.0-beta1/#/elements/vaadin-select)
10
+ [API documentation ↗](https://vaadin.com/components/vaadin-select/html-api)
16
11
 
17
-
18
- [&lt;vaadin-select&gt;](https://vaadin.com/components/vaadin-select) is a Web Component similar to a native browser select element, part of the [Vaadin components](https://vaadin.com/components).
12
+ [![npm version](https://badgen.net/npm/v/@vaadin/vaadin-select)](https://www.npmjs.com/package/@vaadin/vaadin-select)
13
+ [![Published on webcomponents.org](https://img.shields.io/badge/webcomponents.org-published-blue.svg)](https://www.webcomponents.org/element/vaadin/vaadin-select)
14
+ [![Published on Vaadin Directory](https://img.shields.io/badge/Vaadin%20Directory-published-00b4f0.svg)](https://vaadin.com/directory/component/vaadinvaadin-select)
15
+ [![Discord](https://img.shields.io/discord/732335336448852018?label=discord)](https://discord.gg/PHmkCKC)
19
16
 
20
17
  <!--
21
18
  ```
package/package.json CHANGED
@@ -10,7 +10,7 @@
10
10
  "repository": "vaadin/vaadin-select",
11
11
  "homepage": "https://vaadin.com/components",
12
12
  "name": "@vaadin/vaadin-select",
13
- "version": "2.4.1",
13
+ "version": "2.4.4",
14
14
  "main": "vaadin-select.js",
15
15
  "author": "Vaadin Ltd",
16
16
  "license": "Apache-2.0",
@@ -25,8 +25,6 @@
25
25
  "theme"
26
26
  ],
27
27
  "resolutions": {
28
- "es-abstract": "1.17.6",
29
- "@types/doctrine": "0.0.3",
30
28
  "inherits": "2.0.3",
31
29
  "samsam": "1.1.3",
32
30
  "supports-color": "3.1.2",
@@ -47,10 +45,9 @@
47
45
  "@vaadin/vaadin-material-styles": "^1.3.2",
48
46
  "@vaadin/vaadin-element-mixin": "^2.4.1"
49
47
  },
50
- "scripts": {
51
- "generate-typings": "gen-typescript-declarations --outDir . --verify"
52
- },
53
- "devDependencies": {
48
+ "devDependencies": {
49
+ "@web-padawan/gen-typescript-declarations": "^1.6.2",
50
+ "web-component-tester": "6.9.2",
54
51
  "@polymer/iron-test-helpers": "^3.0.0",
55
52
  "@polymer/iron-component-page": "^4.0.0",
56
53
  "@polymer/iron-form": "^3.0.0",
@@ -60,5 +57,9 @@
60
57
  "@vaadin/vaadin-demo-helpers": "^3.1.0",
61
58
  "@vaadin/vaadin-button": "^2.4.0",
62
59
  "@vaadin/vaadin-icons": "^4.3.1"
60
+ },
61
+ "scripts": {
62
+ "generate-typings": "gen-typescript-declarations --outDir . --verify",
63
+ "test": "wct --npm"
63
64
  }
64
65
  }
@@ -15,6 +15,22 @@ $_documentContainer.innerHTML = `<dom-module id="vaadin-select-overlay-styles" t
15
15
  align-items: flex-start;
16
16
  justify-content: flex-start;
17
17
  }
18
+
19
+ :host([bottom-aligned]) {
20
+ justify-content: flex-end;
21
+ }
22
+
23
+ :host([right-aligned]) {
24
+ align-items: flex-end;
25
+ }
26
+
27
+ :host([dir="rtl"]) {
28
+ align-items: flex-end;
29
+ }
30
+
31
+ :host([dir="rtl"][right-aligned]) {
32
+ align-items: flex-start;
33
+ }
18
34
  </style>
19
35
  </template>
20
36
  </dom-module>`;
@@ -178,7 +178,7 @@ class SelectElement extends
178
178
  }
179
179
 
180
180
  static get version() {
181
- return '2.4.0';
181
+ return '2.4.4';
182
182
  }
183
183
 
184
184
  static get properties() {
@@ -405,6 +405,10 @@ class SelectElement extends
405
405
  * Manually invoke existing renderer.
406
406
  */
407
407
  render() {
408
+ if (!this._overlayElement) {
409
+ return;
410
+ }
411
+
408
412
  this._overlayElement.render();
409
413
  if (this._menuElement && this._menuElement.items) {
410
414
  this._updateSelectedItem(this.value, this._menuElement.items);
@@ -562,13 +566,9 @@ class SelectElement extends
562
566
  this._setPosition();
563
567
  window.addEventListener('scroll', this._boundSetPosition, true);
564
568
  } else if (wasOpened) {
565
- if (this._phone) {
566
- this._setFocused(false);
567
- } else {
568
- this.focusElement.focus();
569
- if (this._openedWithFocusRing) {
570
- this.focusElement.setAttribute('focus-ring', '');
571
- }
569
+ this.focusElement.focus();
570
+ if (this._openedWithFocusRing) {
571
+ this.focusElement.setAttribute('focus-ring', '');
572
572
  }
573
573
  this.validate();
574
574
  window.removeEventListener('scroll', this._boundSetPosition, true);
@@ -680,17 +680,22 @@ class SelectElement extends
680
680
  /** @private */
681
681
  _setPosition() {
682
682
  const inputRect = this._inputElement.shadowRoot.querySelector('[part~="input-field"]').getBoundingClientRect();
683
+ const viewportWidth = Math.min(window.innerWidth, document.documentElement.clientWidth);
683
684
  const viewportHeight = Math.min(window.innerHeight, document.documentElement.clientHeight);
684
- const bottomAlign = inputRect.top > (viewportHeight - inputRect.height) / 2;
685
+ const shouldAlignRight = this.__shouldAlignRight(inputRect, viewportWidth);
686
+ const shouldAlignBottom = this.__shouldAlignBottom(inputRect, viewportHeight);
685
687
 
686
- const isRtl = this.getAttribute('dir') === 'rtl';
687
- if (isRtl) {
688
- this._overlayElement.style.right = document.documentElement.clientWidth - inputRect.right + 'px';
688
+ if (shouldAlignRight) {
689
+ this._overlayElement.setAttribute('right-aligned', '');
690
+ this._overlayElement.style.right = (viewportWidth - inputRect.right) + 'px';
691
+ this._overlayElement.style.removeProperty('left');
689
692
  } else {
693
+ this._overlayElement.removeAttribute('right-aligned');
690
694
  this._overlayElement.style.left = inputRect.left + 'px';
695
+ this._overlayElement.style.removeProperty('right');
691
696
  }
692
697
 
693
- if (bottomAlign) {
698
+ if (shouldAlignBottom) {
694
699
  this._overlayElement.setAttribute('bottom-aligned', '');
695
700
  this._overlayElement.style.removeProperty('top');
696
701
  this._overlayElement.style.bottom = (viewportHeight - inputRect.bottom) + 'px';
@@ -703,6 +708,42 @@ class SelectElement extends
703
708
  this._overlayElement.updateStyles({'--vaadin-select-text-field-width': inputRect.width + 'px'});
704
709
  }
705
710
 
711
+ /** @private */
712
+ __shouldAlignRight(targetRect, viewportWidth) {
713
+ const isRTL = this.getAttribute('dir') === 'rtl';
714
+ const spaceLeft = targetRect.left / viewportWidth;
715
+ const spaceRight = (viewportWidth - targetRect.right) / viewportWidth;
716
+
717
+ if (isRTL) {
718
+ // When RTL mode, should align the dropdown right
719
+ // as long as there is enough space on the left side.
720
+ //
721
+ // Default alignment for RTL:
722
+ //
723
+ // _____Select_____
724
+ // ––––––––––––––––––––––––––
725
+ // | Dropdown |
726
+ // ––––––––––––––––––––––––––
727
+ return spaceLeft > 0.3;
728
+ }
729
+
730
+ // When LTL mode, should align the dropdown right
731
+ // only when there is not enough space on the right side.
732
+ //
733
+ // Default alignment for LTL:
734
+ //
735
+ // _____Select_____
736
+ // ––––––––––––––––––––––––––
737
+ // | Dropdown |
738
+ // ––––––––––––––––––––––––––
739
+ return spaceRight < 0.3;
740
+ }
741
+
742
+ /** @private */
743
+ __shouldAlignBottom(targetRect, viewportHeight) {
744
+ return targetRect.top > (viewportHeight - targetRect.height) / 2;
745
+ }
746
+
706
747
  /**
707
748
  * Returns true if `value` is valid, and sets the `invalid` flag appropriately.
708
749
  *
@@ -105,10 +105,6 @@ const $_documentContainer = html`<dom-module id="lumo-select" theme-for="vaadin-
105
105
  --_lumo-item-selected-icon-display: block;
106
106
  }
107
107
 
108
- :host([bottom-aligned]) {
109
- justify-content: flex-end;
110
- }
111
-
112
108
  [part~="overlay"] {
113
109
  min-width: var(--vaadin-select-text-field-width);
114
110
  }
@@ -55,10 +55,6 @@ const $_documentContainer = html`<dom-module id="material-select" theme-for="vaa
55
55
  </dom-module><dom-module id="material-select-overlay" theme-for="vaadin-select-overlay">
56
56
  <template>
57
57
  <style include="material-menu-overlay">
58
- :host([bottom-aligned]) {
59
- justify-content: flex-end;
60
- }
61
-
62
58
  [part="overlay"] {
63
59
  min-width: var(--vaadin-select-text-field-width);
64
60
  }