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

Input docs to site #2297

Merged
merged 42 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
314106d
input
libertymayc Aug 24, 2023
78cc10e
input
libertymayc Aug 24, 2023
4c30ac0
prettier
libertymayc Aug 24, 2023
76b2920
typo
libertymayc Aug 24, 2023
0007cf3
input tweaks
libertymayc Aug 29, 2023
5caae6d
input tweaks
libertymayc Aug 29, 2023
73fac22
Merge branch 'main' into add-input-docs
libertymayc Aug 29, 2023
2b038e1
Update site/docs/components/input/accessibility.mdx
libertymayc Aug 30, 2023
a9fb82c
Update site/docs/components/input/examples.mdx
libertymayc Aug 30, 2023
595aaf2
Update site/docs/components/input/usage.mdx
libertymayc Aug 30, 2023
e48499a
Update site/docs/components/input/accessibility.mdx
libertymayc Aug 30, 2023
e65d6bd
Update site/docs/components/input/accessibility.mdx
libertymayc Aug 30, 2023
d4cbbb0
Update site/docs/components/input/accessibility.mdx
libertymayc Aug 30, 2023
b60dbcf
Update site/docs/components/input/usage.mdx
libertymayc Aug 30, 2023
8289de7
Update site/docs/components/input/examples.mdx
libertymayc Aug 30, 2023
2d10d77
Update site/docs/components/input/examples.mdx
libertymayc Aug 30, 2023
b1a0641
Update site/docs/components/input/accessibility.mdx
libertymayc Aug 30, 2023
7571931
Update site/docs/components/input/accessibility.mdx
libertymayc Aug 30, 2023
3c9cd78
Update site/docs/components/input/examples.mdx
libertymayc Aug 30, 2023
39edee7
Update site/docs/components/input/examples.mdx
libertymayc Aug 30, 2023
a3d606e
Update site/docs/components/input/examples.mdx
libertymayc Aug 30, 2023
b6be57d
Update site/docs/components/input/examples.mdx
libertymayc Aug 30, 2023
68ec7a9
Update site/docs/components/input/examples.mdx
libertymayc Aug 30, 2023
e26530f
Update site/docs/components/input/accessibility.mdx
libertymayc Aug 30, 2023
ad1dce3
Update site/docs/components/input/accessibility.mdx
libertymayc Aug 30, 2023
b383efa
Update site/docs/components/input/accessibility.mdx
libertymayc Aug 30, 2023
f8d5b94
prettier
libertymayc Aug 30, 2023
1286edb
Update site/docs/components/input/accessibility.mdx
libertymayc Aug 30, 2023
f57c661
Update site/docs/components/input/accessibility.mdx
libertymayc Aug 30, 2023
4f3ea5b
Update site/docs/components/input/accessibility.mdx
libertymayc Aug 30, 2023
d39f12a
Update site/docs/components/input/examples.mdx
libertymayc Aug 30, 2023
1b13d21
Update site/docs/components/input/examples.mdx
libertymayc Aug 30, 2023
b15381d
Update site/docs/components/input/examples.mdx
libertymayc Aug 30, 2023
f8e3971
Update site/docs/components/input/accessibility.mdx
libertymayc Aug 30, 2023
ff1c16f
Update site/docs/components/input/examples.mdx
libertymayc Aug 30, 2023
3de237b
Update site/docs/components/input/accessibility.mdx
libertymayc Aug 30, 2023
a6705e8
v
libertymayc Aug 30, 2023
00c6ec4
Merge remote-tracking branch 'origin/add-input-docs' into add-input-docs
libertymayc Aug 30, 2023
334dd55
prettier
libertymayc Aug 30, 2023
1949da5
Merge branch 'main' into add-input-docs
libertymayc Aug 30, 2023
1aead63
Merge branch 'main' into add-input-docs
libertymayc Aug 30, 2023
61522ed
Merge branch 'main' into add-input-docs
james-nash Aug 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
89 changes: 89 additions & 0 deletions site/docs/components/input/accessibility.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
---
title: Input
layout: DetailComponent
sidebar:
exclude: true
data:
$ref: ./#/data
---


- Wrap Input in a [Form Field](/salt/components/form-field) to make it accessible within a form. This will provide the field with a visible label, help text and a status message for validation feedback.
libertymayc marked this conversation as resolved.
Show resolved Hide resolved
libertymayc marked this conversation as resolved.
Show resolved Hide resolved

- Text that extends beyond the visible area of Input is clipped. This behavior is common to all states, i.e., default, read-only and disabled—whether or not the input has focus. To view the text in its entirety, the user can traverse the characters using the cursor.

<LivePreviewControls>
<LivePreview componentName="input" exampleName="EmptyReadonlyMarker" >

### Empty Read-only Marker

For accessibility purposes, we recommend you use the `emptyReadOnlyMarker` prop to add a marker for empty read-only fields. This ensures it’s clear that for the current selection or configuration a value is not necessary.

</LivePreview>
</LivePreviewControls>

### Keyboard interactions

<KeyboardControls>
<KeyboardControl keyOrCombos="Tab">

- If focus is above the Input, Tab key press moves focus onto the input. The text will be highlighted. If the input area is empty, the text cursor is displayed.
- If the input is disabled, Tab key press will skip the input.
- If the input has focus, Tab moves focus out of the input, to next focusable component in the tab order.

</KeyboardControl>
<KeyboardControl keyOrCombos="Shift + Tab">

If focused, Shift + Tab moves focus out of the component to the previous component in the tab order.

</KeyboardControl>
<KeyboardControl keyOrCombos="Enter">

If an interactive adornment, e.g., a button, has focus, the element is activated.

</KeyboardControl>
<KeyboardControl keyOrCombos="Space">

- When the Input area has focus, a space character is inserted at the point where the text cursor is positioned.
libertymayc marked this conversation as resolved.
Show resolved Hide resolved
- If an interactive adornment, e.g., a button, has focus, the element is activated.

</KeyboardControl>
<KeyboardControl keyOrCombos="Right Arrow">

When the Input area has focus:
libertymayc marked this conversation as resolved.
Show resolved Hide resolved

- If text is highlighted, the highlight is removed and the text cursor is positioned at the right edge of the highlight.
- If the text cursor is displayed, it is positioned on the alternative side of the following character. If is there is no following character, there is no effect.

</KeyboardControl>
<KeyboardControl keyOrCombos="Left Arrow">

When the Input area has focus:
libertymayc marked this conversation as resolved.
Show resolved Hide resolved

- If text is highlighted, the highlight is removed and the text cursor is positioned at the left edge of the highlight.
- If the text cursor is displayed, it is positioned on the alternative side of the following character. If is there is no preceding character, there is no effect.

</KeyboardControl>
<KeyboardControl keyOrCombos="Shift + Left Arrow, Shift + Right Arrow">

Drags selection over text characters, one at a time.

</KeyboardControl>
<KeyboardControl keyOrCombos="Backspace">

When Input area has focus and:
- Text is highlighted, all highlighted characters are removed.
- The text cursor is positioned to the right of text, the preceding character is removed.

</KeyboardControl>
<KeyboardControl keyOrCombos="Alphanumeric/Special keys">

When the Input area has focus, the relevant character is inserted at the point where the text cursor is positioned.
libertymayc marked this conversation as resolved.
Show resolved Hide resolved

</KeyboardControl>
<KeyboardControl keyOrCombos="Control/Command + A">

Highlights all strings within the field.

</KeyboardControl>
</KeyboardControls>
107 changes: 107 additions & 0 deletions site/docs/components/input/examples.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
---
title: Input
layout: DetailComponent
sidebar:
exclude: true
data:
$ref: ./#/data
---

<LivePreviewControls>
<LivePreview componentName="input" exampleName="Primary" >

### Primary

Input comprises value text and a focus ring. The component is initially empty and then, once it has focus, it accepts text on a single line only.

The default variant for Input is "primary".

</LivePreview>
<LivePreview componentName="input" exampleName="Secondary" >

### Secondary

Input has a "secondary" variant.

For recommendations on variant choice, see the [Forms pattern](salt/patterns/forms).

</LivePreview>
<LivePreview componentName="input" exampleName="Disabled" >

### Disabled

You can disable Input, with no resultant action when the user interacts with it.

</LivePreview>
<LivePreview componentName="input" exampleName="Readonly" >

### Read-only

You can set Input to a read-only state. The value text can’t be edited in this state, but it can be highlighted and copied.

By default, the marker is set to an em dash. If your application requires a different marker it can be set via the `emptyReadOnlyMarker` prop.

- Use the read-only state when the value is necessary for the users flow or current task but cannot be edited, for example, because of user permissions.

</LivePreview>
<LivePreview componentName="input" exampleName="EmptyReadonlyMarker" >

### Placeholder

You can use a placeholder to prompt user input if no default value is provided.

- Placeholder text should never be used to provide the user with contextual help since it will be removed when the user starts typing and does not meet minimum contrast requirements. Doing so is a WCAG failure. Instead, use helper text beneath the field to provide instructions or directions which are necessary to complete the field, and reserve the placeholder text to support the help message, or provide an example of the suggested content.

More information can be found [in the W3C form instructions](https://www.w3.org/WAI/tutorials/forms/instructions/).

</LivePreview>
<LivePreview componentName="input" exampleName="Spellcheck" >

### Spellcheck

Turn automatic spellchecking on using `inputProps`.

</LivePreview>
<LivePreview componentName="input" exampleName="StaticAdornments" >

### Static adornments

You can add custom adornments at the beginning or end of the Input field using the `startAdornment` and `endAdornment` props.

Start adornments are typically used to describe the purpose of the field (e.g., a phone number input, or a currency), whereas end adornments are typically used to indicate a reveal of more information (e.g., using an arrow icon) or to trigger a new UI (such as a date picker).

Salt [Text](/salt/components/text) and [Icons](/salt/foundations/iconography) can be used to add Salt styled alphanumeric text or symbols as adornments. Multiple start or end adornments should be wrapped in a parent container and passed to the respective prop as a single fragment. Adornments can be dynamic, with their value depending on the current state.

</LivePreview>
<LivePreview componentName="input" exampleName="ButtonAdornments" >

### Button adornments

You can use [Button](/salt/components/button) at the beginning or end of the Input field with the `startAdornment` and `endAdornment` props. Buttons can allow for custom interactivity within the Input field itself, or elsewhere in the app via the Input field.

Ensure to make your interactive Buttons disabled or read-only should it match the state of the containing Input field.

</LivePreview>
<LivePreview componentName="input" exampleName="Validation" >

### Validation

Input can show validation states (warning, success, error) with the prop `validationStatus`.

- Use the error state to alert the user of a critical issue that’s related to the input. This issue, which may jeopardize completion of the task, usually requires action from the user to resolve the error.

- Display the warning state when you need to alert the user of a potential issue—that won’t prevent the user from continuing with the task, but may cause errors if it’s not addressed.

</LivePreview>
<LivePreview componentName="input" exampleName="TextAlignment" >

### Text Alignment

Text is left-aligned by default. Use the `textAlign` prop to change the alignment to “center” or “right”.

- Numeric values are often displayed right aligned to make them easier to compare. However, sometimes number fields are unrelated or are mixed with text fields in a form, so left-alignment may promote better visual flow. Consider your use case when deciding on Input field alignment.

You may choose to center-align an input field to bring emphasis to a value. However, this should be the exception and used sparingly.

</LivePreview>
</LivePreviewControls>
13 changes: 13 additions & 0 deletions site/docs/components/input/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
title: Input
data:
description: Input provides an editable field in which users can enter text and numeric values. It is best used for short freeform content and data entry.
sourceCodeUrl: "https://github.com/jpmorganchase/salt-ds/blob/main/packages/core/src/input/Input.tsx"
package:
name: "@salt-ds/core"
initialVersion: "1.0.0"
libertymayc marked this conversation as resolved.
Show resolved Hide resolved
alsoKnownAs: ["Text Field", "Text Box"]
relatedComponents: [{ name: "Multiline Input", relationship: "similarTo" }]
james-nash marked this conversation as resolved.
Show resolved Hide resolved
stickerSheet: ""
layout: DetailComponent
---
29 changes: 29 additions & 0 deletions site/docs/components/input/usage.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
title: Input
layout: DetailComponent
sidebar:
exclude: true
data:
$ref: ./#/data
---

### When to use Input

- To ask a user a subjective question to which user responses will vary and the length of their answer is likely to be less than a single line.
- To avoid misleading users, set the width to correlates to the length of the answer you’re expecting. For example, an input for a three-digit value should not be wide enough to accommodate a sentence worth of characters. See [Forms pattern](/salt/patterns/forms) for more information on layout.

#### When not to use Input

When the content is likely to exceed a single line. Instead, use a [Multiline Input](/salt/components/multiline-input). Input field width and height should always reflect the amount of content expected in the field.

### Import

To import Input from the core Salt package, use:

```js
import { Input } from "@salt-ds/core";
```

### Props

<PropsTable componentName="Input" />
109 changes: 109 additions & 0 deletions site/src/examples/input/ButtonAdornments.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import { ReactElement } from "react";
import { Button, FlowLayout, Input } from "@salt-ds/core";
import {
NoteIcon,
SendIcon,
FlagIcon,
RefreshIcon,
CloseIcon,
} from "@salt-ds/icons";

export const ButtonAdornments = (): ReactElement => (
<FlowLayout style={{ width: "266px" }}>
<Input
startAdornment={
<Button>
<NoteIcon />
</Button>
}
defaultValue="Value"
/>
<Input
endAdornment={
<Button variant="cta">
<RefreshIcon />
</Button>
}
defaultValue="Value"
/>
<Input
startAdornment={
<>
<Button>
<SendIcon />
</Button>
<Button variant="cta">
<FlagIcon />
</Button>
</>
}
defaultValue="Value"
/>
<Input
endAdornment={
<>
<Button variant="secondary">
<CloseIcon />
</Button>
<Button variant="cta">
<FlagIcon />
</Button>
</>
}
defaultValue="Value"
/>
<Input
disabled
endAdornment={
<>
<Button disabled>
<SendIcon />
</Button>
<Button disabled variant="secondary">
<CloseIcon />
</Button>
<Button disabled variant="cta">
<FlagIcon />
</Button>
</>
}
defaultValue="Value"
/>
<Input
readOnly
startAdornment={
<>
<Button disabled>
<SendIcon />
</Button>
<Button disabled variant="secondary">
<CloseIcon />
</Button>
<Button disabled variant="cta">
<FlagIcon />
</Button>
</>
}
defaultValue="Value"
/>
<Input
disabled
startAdornment={
<>
<Button disabled>
<CloseIcon />
</Button>
<Button disabled variant="secondary">
<FlagIcon />
</Button>
</>
}
endAdornment={
<Button variant="cta" disabled>
<SendIcon />
</Button>
}
defaultValue="Value"
/>
</FlowLayout>
);
6 changes: 6 additions & 0 deletions site/src/examples/input/Disabled.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { ReactElement } from "react";
import { Input } from "@salt-ds/core";

export const Disabled = (): ReactElement => (
<Input defaultValue="Value" disabled style={{ width: "256px" }} />
);
9 changes: 9 additions & 0 deletions site/src/examples/input/EmptyReadonlyMarker.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { ReactElement } from "react";
import { FlowLayout, Input } from "@salt-ds/core";

export const EmptyReadonlyMarker = (): ReactElement => (
<FlowLayout style={{ width: "256px" }}>
<Input readOnly />
<Input readOnly emptyReadOnlyMarker="*" />
</FlowLayout>
);
10 changes: 10 additions & 0 deletions site/src/examples/input/Placeholder.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { ReactElement } from "react";
import { FlowLayout, Input } from "@salt-ds/core";

export const Placeholder = (): ReactElement => (
<FlowLayout style={{ width: "256px" }}>
<Input placeholder={"Enter a value"} />
<Input disabled placeholder={"Enter a value"} />
<Input readOnly placeholder={"Enter a value"} />
</FlowLayout>
);
6 changes: 6 additions & 0 deletions site/src/examples/input/Primary.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { ReactElement } from "react";
import { Input } from "@salt-ds/core";

export const Primary = (): ReactElement => (
<Input defaultValue="Value" style={{ width: "256px" }} />
);
6 changes: 6 additions & 0 deletions site/src/examples/input/Readonly.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { ReactElement } from "react";
import { Input } from "@salt-ds/core";

export const Readonly = (): ReactElement => (
<Input defaultValue="Value" style={{ width: "256px" }} readOnly />
);
Loading
Loading