Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(text-field): decouple from FAST foundation (VIV-2029) #2007

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libs/components/src/lib/text-field/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,5 +223,6 @@ The `helper-text` slot allows you to use rich content as the text-field's helper
| ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `checkValidity` | Returns `true` if the element's `value` passes validity checks; otherwise, returns `false` and fires an `invalid` event at the element. |
| `reportValidity` | Returns `true` if the element's `value` passes validity checks; otherwise, returns `false`, fires an `invalid` event at the element, and (if the event isn't canceled) reports the problem to the user. |
| `select` | Selects all the text in the text field |

</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { FormAssociated, FoundationElement } from '@microsoft/fast-foundation';

class _TextField extends FoundationElement {}
// eslint-disable-next-line @typescript-eslint/naming-convention
interface _TextField extends FormAssociated {}

export class FormAssociatedTextField extends FormAssociated(_TextField) {
proxy = document.createElement('input');
}
27 changes: 27 additions & 0 deletions libs/components/src/lib/text-field/text-field.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,15 @@ describe('vwc-text-field', () => {
await elementUpdated(element);
expect(getInput()?.hasAttribute('autofocus')).toEqual(true);
});

it('should focus the input element when connected', async () => {
element = (await fixture(
`<${COMPONENT_TAG_NAME} autofocus></${COMPONENT_TAG_NAME}>`
)) as TextField;
await elementUpdated(element);

expect(document.activeElement).toEqual(getInput());
});
});

describe('inputmode', function () {
Expand Down Expand Up @@ -238,6 +247,14 @@ describe('vwc-text-field', () => {
});
});

describe('spellcheck', function () {
it('should set spellcheck attribute on the input', async function () {
element.spellcheck = true;
await elementUpdated(element);
expect(getInput()?.hasAttribute('spellcheck')).toBe(true);
});
});

describe('maxlength', function () {
const value = '8';
const propertyName = 'maxlength';
Expand Down Expand Up @@ -634,6 +651,16 @@ describe('vwc-text-field', () => {
});
});

describe('select method', function () {
it('should call select on the input', async function () {
getInput().select = jest.fn();

element.select();

expect(getInput().select).toHaveBeenCalled();
});
});

describe('accessible helper text', function () {
function getAccessibleDescription() {
const describedBy = element
Expand Down
Loading
Loading