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

Adds TextInput as a new web component #27348

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
7f9af9e
radio init
brianchristopherbrady Mar 3, 2023
70c55e0
styles radio
brianchristopherbrady Mar 3, 2023
f3cb7f4
Merge branch 'microsoft:web-components-v3' into web-components-v3
brianchristopherbrady Mar 3, 2023
a72d10f
reverts branch
brianchristopherbrady Mar 3, 2023
2941fa7
Merge branch 'web-components-v3' of https://github.com/brianchristoph…
brianchristopherbrady Mar 3, 2023
9b350fc
Merge branch 'microsoft:web-components-v3' into web-components-v3
brianchristopherbrady Mar 20, 2023
2cf59ce
input spec init
brianchristopherbrady Mar 20, 2023
79b6bff
cleans up spec
brianchristopherbrady Mar 20, 2023
5558b93
formatting
brianchristopherbrady Mar 20, 2023
3c045c3
updates component name to text input
brianchristopherbrady Mar 20, 2023
2370967
updates component name in spec
brianchristopherbrady Mar 20, 2023
0040fbd
text input init
brianchristopherbrady Mar 22, 2023
f36d8c6
adds text input options
brianchristopherbrady Mar 22, 2023
9be3a2e
styles text input
brianchristopherbrady Mar 23, 2023
630632f
updates text input styles
brianchristopherbrady Mar 23, 2023
5786394
adds input size attribute and styles
brianchristopherbrady Mar 23, 2023
0d9fa2e
updates text input storybook
brianchristopherbrady Mar 27, 2023
c04acf4
text input: adds properties to class
brianchristopherbrady Mar 27, 2023
8afab54
text-input: re-exports TextFieldType as TextInputType
brianchristopherbrady Mar 27, 2023
7a001f5
text input: fixes export names
brianchristopherbrady Mar 27, 2023
bb80c49
text input: updates underline styles
brianchristopherbrady Mar 27, 2023
0d8f5da
text-input: exports text-input from package.json
brianchristopherbrady Mar 28, 2023
827cd99
removes dead code
brianchristopherbrady Mar 28, 2023
821ccdb
text-input: removes default attr values
brianchristopherbrady Mar 28, 2023
4504f6e
text-input: updates icon sizes
brianchristopherbrady Mar 28, 2023
3dbcaf5
text-input: updates block vs inline implimentation
brianchristopherbrady Mar 29, 2023
a0d7c34
text-input: updates docs
brianchristopherbrady Mar 29, 2023
170aa17
text-input: adds styling support for icons and text passed through st…
brianchristopherbrady Mar 29, 2023
9eba387
text-input: updates border styles
brianchristopherbrady Mar 30, 2023
f8d58f0
input: updates storybook content
brianchristopherbrady Mar 30, 2023
b1f644e
updates README
brianchristopherbrady Mar 30, 2023
6ac34cf
text-input: adds filled non shadow variants
brianchristopherbrady Mar 30, 2023
78eceaf
text-input: modifies storybook examples
brianchristopherbrady Mar 31, 2023
e630555
text-input: removes dead import
brianchristopherbrady Mar 31, 2023
fb73475
addresses PR feedback
brianchristopherbrady Apr 4, 2023
939536c
text input: updates styles
brianchristopherbrady Apr 6, 2023
e97bec8
text input: yarn change
brianchristopherbrady Apr 6, 2023
54cb7c4
text input: updates README and styles
brianchristopherbrady Apr 6, 2023
3de0b20
text input: shorthands css property
brianchristopherbrady Apr 10, 2023
43df042
Merge branch 'web-components-v3' into user/brianbrady/text-input
brianchristopherbrady Apr 11, 2023
5b58ec4
textinput: fixes ts errors
brianchristopherbrady May 5, 2023
0581dc5
textinput: updates attribute name
brianchristopherbrady May 5, 2023
efe2674
textinput: uses fluent-label in stories
brianchristopherbrady May 5, 2023
6b8eb42
Merge branch 'web-components-v3' into user/brianbrady/text-input
brianchristopherbrady May 5, 2023
2154362
textinput: updates control size type name
brianchristopherbrady May 9, 2023
026e324
Merge branch 'user/brianbrady/text-input' of https://github.com/brian…
brianchristopherbrady May 9, 2023
c3c2313
textinput: updates storybook
brianchristopherbrady May 9, 2023
5f8be41
textinput: updates type
brianchristopherbrady May 9, 2023
1f87e19
textinput: updates story styles
brianchristopherbrady May 9, 2023
f65335f
Merge branch 'web-components-v3' into user/brianbrady/text-input
brianchristopherbrady May 9, 2023
6f9584f
Update change/@fluentui-web-components-ec003fd2-a453-4e83-b620-9ec9f3…
brianchristopherbrady May 22, 2023
cb1a2d2
text-input: addresses feedback
brianchristopherbrady May 22, 2023
bf6d213
text-input: alphabetize exports, removes setting default attr value
brianchristopherbrady May 22, 2023
e01a615
Merge branch 'web-components-v3' into user/brianbrady/text-input
brianchristopherbrady May 31, 2023
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "feat(text-input): add TextInput as a new web component",
"packageName": "@fluentui/web-components",
"email": "brianbrady@microsoft.com",
"dependentChangeType": "patch"
}
4 changes: 4 additions & 0 deletions packages/web-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@
"types": "./dist/esm/text/define.d.ts",
"default": "./dist/esm/text/define.js"
},
"./text-input": {
"types": "./dist/esm/text-input/define.d.ts",
"default": "./dist/esm/text-input/define.js"
},
"./toggle-button": {
"types": "./dist/esm/toggle-button/define.d.ts",
"default": "./dist/esm/toggle-button/define.js"
Expand Down
1 change: 1 addition & 0 deletions packages/web-components/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export * from './tabs/index.js';
export * from './tab/index.js';
export * from './tab-panel/index.js';
export * from './text/index.js';
export * from './text-input/index.js';
export * from './toggle-button/index.js';

export * from './theme/index.js';
155 changes: 155 additions & 0 deletions packages/web-components/src/text-input/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
# TextInput

> An implementation of a [text input](https://w3c.github.io/html-reference/input.text.html) as a form-connected web-component.
> <br />

## **Design Spec**

[Link to Text Input Design Spec in Figma](https://www.figma.com/file/TvHmWjZYxwtI9Tz6v5BT7E/Input?node-id=2366-657&t=UNSOfCD3St9ffppx-0)

<br />

## **Engineering Spec**

Fluent WC3 Text Input extends from the [FAST Text Field](https://explore.fast.design/components/fast-text-field) and is intended to be as close to the Fluent UI React 9 Input implementation as possible. However, due to the nature of web components there will not be 100% parity between the two.

<br />

## Class: `TextInput`

<br />

### **Component Name**

`<fluent-text-input>`

<br />

### **Variables**

| Name | Description | Type |
| ---------------------- | ------------------------------------ | ---------------------------------------------------------------------------------------------------------------- |
| `TextInputControlSize` | Size variations for text input | `{ small: "small", medium: "medium", large: "large" }` |
| `TextInputAppearance` | Appearance variations for text input | `{ outline: "outline", underline: "underline", filledLighter: "filled-lighter", filledDarker: "filled-darker" }` |
| `TextInputType` | Text input types | `{ email: "email", password: "password", tel: "tel", text: "text", url: "url" }` |

<br />

### **Fields**

| Name | Privacy | Type | Default | Description |
| --------------- | ------- | ---------------------- | ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `appearance` | public | `TextInputAppearance` | `TextInputAppearance.outline` | Sets appearance of text input. |
| `autofocus` | public | `boolean` | `false` | Indicates element should get focus after the page finishes loading.. |
| `disabled` | public | `boolean` | `false` | Disables text input |
| `list` | public | `string` | | Allows associating a `datalist` to an element by `id` |
| `maxlength` | public | `number` | | The maximum number of characters a user can enter |
| `minlength` | public | `number` | | The minimum number of characters a user can enter |
| `name` | public | `string` | | The name of the control |
| `pattern` | public | `string` | | A regular expression the text input's contents must match in order to be valid |
| `placeholder` | public | `string` | | An exemplar value to display in the text input field whenever it is empty |
| `readonly` | public | `boolean` | `false` | The text input should be submitted with the form but should not be editable |
| `required` | public | `boolean` | `false` | Sets the text input as required |
| `size` | public | `number` | | A number indicating how many characters wide the input field should be |
| `spellcheck` | public | `boolean` | `false` | Controls whether or not to enable spell checking for the text input, or if the default spell checking configuration should be used |
| `type` | public | `TextInputType` | `TextInputType.text` | Sets the size of the text input |
| `current-value` | public | | | Stores the current value of an input element. This attribute is commonly used in web development frameworks like Angular and React, where the value of the input element is managed by the framework. By using the current-value attribute, you can ensure that the input element always displays the correct value, even if it is changed by the framework or another JavaScript code. This attribute can also be used to set the initial value of an input element. [link: `current-value` RFC](https://github.com/microsoft/fast/issues/5119) |
| `control-size` | public | `TextInputControlSize` | `TextInputControlSize.medium` | Sets the size of the component |

<br />

### **Methods**

| Name | Privacy | Description |
| ---------- | ------- | ------------------------------------------------- |
| `select` | public | Selects all the text in the text field |
| `validate` | public | {@inheritDoc (FormAssociated:interface).validate} |

### **Events**

| Name | Type | Description | Inherited From |
| -------- | ---- | --------------------------- | -------------- |
| `change` | | Fires a custom change event | |

<br />

### **Attributes**

| Name | Field |
| -------------- | ----------- |
| `appearance` | appearance |
| `autofocus` | autofocus |
| `list` | list |
| `maxlength` | maxlength |
| `minlength` | minlength |
| `pattern` | pattern |
| `placeholder` | placeholder |
| `readonly ` | readonly |
| `size` | size |
| `spellcheck` | spellcheck |
| `type` | type |
| `control-size` | type |

<br />

### **Slots**

| Name | Description |
| ------- | ---------------------------------------------------------------------------- |
| `start` | used to place content at the start of the text input within the input border |
| `end` | used to place content at the end of the text input within the input border |
| | The default slot for text input content |

<br />

**Block v.s Inline**

The Fluent UI `TextInput` component design spec offers two appearance variations for the display property - block (default) and inline. To achieve the inline variation, users should apply their own custom CSS.

```css
/* all instances */

fluent-text-input {
display: inline-flex;
align-items: center;
}

/* class instances */

fluent-text-input.inline {
display: inline-flex;
align-items: center;
}
```

<br />
<hr />
<br />

## **Accessibility**

[W3C Text Input Spec](https://w3c.github.io/html-reference/input.text.html)

<br />

### **WAI-ARIA Roles, States, and Properties**

This component supports ARIA attributes that inherit from the [ARIA Global States and Properties](https://www.w3.org/TR/wai-aria-1.2/#global_states).

<br />
<hr />
<br />

## **Preparation**

### **Fluent Web Component v3 v.s Fluent React 9**

<br />

**Component and Slot Mapping**

| Fluent UI React 9 | Fluent Web Components 3 |
| ----------------- | ----------------------- |
| `<Input>` | `<fluent-text-input>` |
| `contentBefore` | `start` |
| `contentAfter` | `end` |
4 changes: 4 additions & 0 deletions packages/web-components/src/text-input/define.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { FluentDesignSystem } from '../fluent-design-system.js';
import { definition } from './text-input.definition.js';

definition.define(FluentDesignSystem.registry);
6 changes: 6 additions & 0 deletions packages/web-components/src/text-input/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export * from './text-input.js';
export * from './text-input.options.js';
export { template as TextInputTemplate } from './text-input.template.js';
export { styles as TextInputStyles } from './text-input.styles.js';
export { definition as TextInputDefinition } from './text-input.definition.js';
export { TextFieldType as TextInputType } from '@microsoft/fast-foundation';
18 changes: 18 additions & 0 deletions packages/web-components/src/text-input/text-input.definition.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { FluentDesignSystem } from '../fluent-design-system.js';
import { TextInput } from './text-input.js';
import { styles } from './text-input.styles.js';
import { template } from './text-input.template.js';

/**
* The Fluent TextInput Element.
*
*
* @public
* @remarks
* HTML Element: \<fluent-text-input\>
*/
export const definition = TextInput.compose({
name: `${FluentDesignSystem.prefix}-text-input`,
template,
styles,
});
34 changes: 34 additions & 0 deletions packages/web-components/src/text-input/text-input.options.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { ValuesOf } from '@microsoft/fast-foundation';

/**
* TextInput size constants
* @public
*/
export const TextInputControlSize = {
small: 'small',
medium: 'medium',
large: 'large',
} as const;

/**
* Applies size styling to TextInput
* @public
*/
export type TextInputControlSize = ValuesOf<typeof TextInputControlSize>;

/**
* TextInput appearance constants
* @public
*/
export const TextInputAppearance = {
outline: 'outline',
underline: 'underline',
filledLighter: 'filled-lighter',
filledDarker: 'filled-darker',
} as const;

/**
* Applies appearance styling to TextInput
* @public
*/
export type TextInputAppearance = ValuesOf<typeof TextInputAppearance>;
Loading