Skip to content

Commit b23c98c

Browse files
authored
refactor!: move password field to new package (#2319)
1 parent a7d2733 commit b23c98c

44 files changed

Lines changed: 220 additions & 554 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎packages/custom-field/package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"devDependencies": {
3636
"@esm-bundle/chai": "^4.3.4",
3737
"@vaadin/email-field": "^22.0.0-alpha1",
38+
"@vaadin/password-field": "^22.0.0-alpha1",
3839
"@vaadin/testing-helpers": "^0.2.1",
3940
"sinon": "^9.2.1"
4041
},

‎packages/custom-field/test/visual/lumo/custom-field.test.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import '@vaadin/email-field/theme/lumo/vaadin-email-field.js';
1212
import '@vaadin/vaadin-text-field/theme/lumo/vaadin-number-field.js';
1313
import '@vaadin/text-area/theme/lumo/vaadin-text-area.js';
1414
import '@vaadin/vaadin-text-field/theme/lumo/vaadin-text-field.js';
15-
import '@vaadin/vaadin-text-field/theme/lumo/vaadin-password-field.js';
15+
import '@vaadin/password-field/theme/lumo/vaadin-password-field.js';
1616
import '@vaadin/vaadin-time-picker/theme/lumo/vaadin-time-picker.js';
1717
import '../../../theme/lumo/vaadin-custom-field.js';
1818
import { CustomField } from '../../../src/vaadin-custom-field.js';

‎packages/custom-field/test/visual/material/custom-field.test.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import '@vaadin/email-field/theme/material/vaadin-email-field.js';
1212
import '@vaadin/vaadin-text-field/theme/material/vaadin-number-field.js';
1313
import '@vaadin/text-area/theme/material/vaadin-text-area.js';
1414
import '@vaadin/vaadin-text-field/theme/material/vaadin-text-field.js';
15-
import '@vaadin/vaadin-text-field/theme/material/vaadin-password-field.js';
15+
import '@vaadin/password-field/theme/material/vaadin-password-field.js';
1616
import '@vaadin/vaadin-time-picker/theme/material/vaadin-time-picker.js';
1717
import '../../../theme/material/vaadin-custom-field.js';
1818
import { CustomField } from '../../../src/vaadin-custom-field.js';

‎packages/password-field/README.md‎

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,54 @@
11
# @vaadin/password-field
22

3-
> ⚠️ Work in progress, please do not use this component yet.
3+
An extension of `vaadin-text-field` component for entering passwords.
44

5-
The new version of `vaadin-password-field` component using slotted `<input>`.
5+
[Live Demo ↗](https://vaadin.com/docs/latest/ds/components/password-field)
6+
7+
```html
8+
<vaadin-password-field label="Password"></vaadin-password-field>
9+
```
10+
11+
## Installation
12+
13+
Install the component:
14+
15+
```sh
16+
npm i @vaadin/password-field --save
17+
```
18+
19+
Once installed, import the component in your application:
20+
21+
```js
22+
import '@vaadin/password-field';
23+
```
24+
25+
## Themes
26+
27+
Vaadin components come with two built-in [themes](https://vaadin.com/docs/latest/ds/customization/using-themes),
28+
Lumo and Material. The [main entrypoint](https://github.com/vaadin/web-components/blob/master/packages/password-field/vaadin-password-field.js)
29+
of the package uses Lumo theme.
30+
31+
To use the Material theme, import the component from the `theme/material` folder:
32+
33+
```js
34+
import '@vaadin/password-field/theme/material/vaadin-password-field.js';
35+
```
36+
37+
You can also import the Lumo version of the component explicitly:
38+
39+
```js
40+
import '@vaadin/password-field/theme/lumo/vaadin-password-field.js';
41+
```
42+
43+
Finally, you can import the un-themed component from the `src` folder to get a minimal starting point:
44+
45+
```js
46+
import '@vaadin/password-field/src/vaadin-password-field.js';
47+
```
48+
49+
## License
50+
51+
Apache License 2.0
52+
53+
Vaadin collects development time usage statistics to improve this product.
54+
For details and to opt-out, see https://github.com/vaadin/vaadin-usage-statistics.

‎packages/password-field/src/vaadin-password-field.d.ts‎

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,54 @@
55
*/
66
import { TextField } from '@vaadin/text-field/src/vaadin-text-field.js';
77

8+
/**
9+
* Fired when the `invalid` property changes.
10+
*/
11+
export type PasswordFieldInvalidChangedEvent = CustomEvent<{ value: boolean }>;
12+
13+
/**
14+
* Fired when the `value` property changes.
15+
*/
16+
export type PasswordFieldValueChangedEvent = CustomEvent<{ value: string }>;
17+
18+
export interface PasswordFieldCustomEventMap {
19+
'invalid-changed': PasswordFieldInvalidChangedEvent;
20+
21+
'value-changed': PasswordFieldValueChangedEvent;
22+
}
23+
24+
export interface PasswordFieldEventMap extends HTMLElementEventMap, PasswordFieldCustomEventMap {}
25+
26+
/**
27+
* `<vaadin-password-field>` is an extension of `<vaadin-text-field>` component for entering passwords.
28+
*
29+
* ```html
30+
* <vaadin-password-field label="Password"></vaadin-password-field>
31+
* ```
32+
*
33+
* ### Styling
34+
*
35+
* See [`<vaadin-text-field>`](#/elements/vaadin-text-field) for the styling documentation.
36+
*
37+
* In addition to `<vaadin-text-field>` parts, here's the list of `<vaadin-password-field>` specific parts:
38+
*
39+
* Part name | Description
40+
* ----------------|----------------------------------------------------
41+
* `reveal-button` | The eye icon which toggles the password visibility
42+
*
43+
* In addition to `<vaadin-text-field>` state attributes, here's the list of `<vaadin-password-field>` specific attributes:
44+
*
45+
* Attribute | Description | Part name
46+
* -------------------|-------------|------------
47+
* `password-visible` | Set when the password is visible | :host
48+
*
49+
* See [Styling Components](https://vaadin.com/docs/latest/ds/customization/styling-components) documentation.
50+
*
51+
* @fires {Event} input - Fired when the value is changed by the user: on every typing keystroke, and the value is cleared using the clear button.
52+
* @fires {Event} change - Fired when the user commits a value change.
53+
* @fires {CustomEvent} invalid-changed - Fired when the `invalid` property changes.
54+
* @fires {CustomEvent} value-changed - Fired when the `value` property changes.
55+
*/
856
declare class PasswordField extends TextField {
957
/**
1058
* Set to true to hide the eye icon which toggles the password visibility.
@@ -30,6 +78,24 @@ declare class PasswordField extends TextField {
3078
* ```
3179
*/
3280
i18n: { reveal: string };
81+
82+
addEventListener<K extends keyof PasswordFieldEventMap>(
83+
type: K,
84+
listener: (this: PasswordField, ev: PasswordFieldEventMap[K]) => void,
85+
options?: boolean | AddEventListenerOptions
86+
): void;
87+
88+
removeEventListener<K extends keyof PasswordFieldEventMap>(
89+
type: K,
90+
listener: (this: PasswordField, ev: PasswordFieldEventMap[K]) => void,
91+
options?: boolean | EventListenerOptions
92+
): void;
93+
}
94+
95+
declare global {
96+
interface HTMLElementTagNameMap {
97+
'vaadin-password-field': PasswordField;
98+
}
3399
}
34100

35101
export { PasswordField };

‎packages/password-field/src/vaadin-password-field.js‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,38 @@ const ownTemplate = html`
1414

1515
let memoizedTemplate;
1616

17+
/**
18+
* `<vaadin-password-field>` is an extension of `<vaadin-text-field>` component for entering passwords.
19+
*
20+
* ```html
21+
* <vaadin-password-field label="Password"></vaadin-password-field>
22+
* ```
23+
*
24+
* ### Styling
25+
*
26+
* See [`<vaadin-text-field>`](#/elements/vaadin-text-field) for the styling documentation.
27+
*
28+
* In addition to `<vaadin-text-field>` parts, here's the list of `<vaadin-password-field>` specific parts:
29+
*
30+
* Part name | Description
31+
* ----------------|----------------------------------------------------
32+
* `reveal-button` | The eye icon which toggles the password visibility
33+
*
34+
* In addition to `<vaadin-text-field>` state attributes, here's the list of `<vaadin-password-field>` specific attributes:
35+
*
36+
* Attribute | Description | Part name
37+
* -------------------|-------------|------------
38+
* `password-visible` | Set when the password is visible | :host
39+
*
40+
* See [Styling Components](https://vaadin.com/docs/latest/ds/customization/styling-components) documentation.
41+
*
42+
* @fires {Event} input - Fired when the value is changed by the user: on every typing keystroke, and the value is cleared using the clear button.
43+
* @fires {Event} change - Fired when the user commits a value change.
44+
* @fires {CustomEvent} invalid-changed - Fired when the `invalid` property changes.
45+
* @fires {CustomEvent} value-changed - Fired when the `value` property changes.
46+
*
47+
* @extends TextField
48+
*/
1749
export class PasswordField extends TextField {
1850
static get is() {
1951
return 'vaadin-password-field';
@@ -252,3 +284,5 @@ export class PasswordField extends TextField {
252284
this._updateToggleState(passwordVisible);
253285
}
254286
}
287+
288+
customElements.define(PasswordField.is, PasswordField);

‎packages/password-field/test/password-field.test.js‎

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ import { expect } from '@esm-bundle/chai';
22
import { sendKeys } from '@web/test-runner-commands';
33
import sinon from 'sinon';
44
import { fixtureSync, focusout } from '@vaadin/testing-helpers';
5-
import { PasswordField } from '../src/vaadin-password-field.js';
6-
7-
customElements.define('vaadin-password-field', PasswordField);
5+
import '../src/vaadin-password-field.js';
86

97
describe('password-field', () => {
108
let passwordField, input, revealButton;
@@ -206,3 +204,27 @@ describe('password-field', () => {
206204
});
207205
});
208206
});
207+
208+
describe('invalid', () => {
209+
let field;
210+
211+
beforeEach(() => {
212+
field = fixtureSync('<vaadin-password-field invalid></vaadin-password-field>');
213+
});
214+
215+
it('should not remove "invalid" state when ready', () => {
216+
expect(field.invalid).to.be.true;
217+
});
218+
});
219+
220+
describe('invalid with value', () => {
221+
let field;
222+
223+
beforeEach(() => {
224+
field = fixtureSync('<vaadin-password-field invalid value="123456"></vaadin-password-field>');
225+
});
226+
227+
it('should not remove "invalid" state when ready', () => {
228+
expect(field.invalid).to.be.true;
229+
});
230+
});
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import '../../vaadin-password-field.js';
2+
3+
import { PasswordFieldInvalidChangedEvent, PasswordFieldValueChangedEvent } from '../../vaadin-password-field.js';
4+
5+
const assertType = <TExpected>(actual: TExpected) => actual;
6+
7+
const field = document.createElement('vaadin-password-field');
8+
9+
field.addEventListener('invalid-changed', (event) => {
10+
assertType<PasswordFieldInvalidChangedEvent>(event);
11+
assertType<boolean>(event.detail.value);
12+
});
13+
14+
field.addEventListener('value-changed', (event) => {
15+
assertType<PasswordFieldValueChangedEvent>(event);
16+
assertType<string>(event.detail.value);
17+
});

‎packages/password-field/test/visual/lumo/password-field.test.js‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ import { fixtureSync } from '@vaadin/testing-helpers/dist/fixture.js';
22
import { sendKeys } from '@web/test-runner-commands';
33
import { visualDiff } from '@web/test-runner-visual-regression';
44
import '../../../theme/lumo/vaadin-password-field.js';
5-
import { PasswordField } from '../../../src/vaadin-password-field.js';
6-
7-
customElements.define('vaadin-password-field', PasswordField);
85

96
describe('password-field', () => {
107
let div, element;

‎packages/password-field/test/visual/material/password-field.test.js‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ import { fixtureSync } from '@vaadin/testing-helpers/dist/fixture.js';
22
import { sendKeys } from '@web/test-runner-commands';
33
import { visualDiff } from '@web/test-runner-visual-regression';
44
import '../../../theme/material/vaadin-password-field.js';
5-
import { PasswordField } from '../../../src/vaadin-password-field.js';
6-
7-
customElements.define('vaadin-password-field', PasswordField);
85

96
describe('password-field', () => {
107
let div, element;

0 commit comments

Comments
 (0)