Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import action from "./examples/action";
import functionSuggestions from "./examples/functionSuggestions";
import errorHandling from "./examples/errorHandling";
import Code, { TableCode, ExtendedTableCode } from "@/common/Code";
import StatusBadge from "@/common/StatusBadge";

const actionTypeString = `{
icon?: string | (React.ReactNode
Expand All @@ -32,13 +33,32 @@ const sections = [
</thead>
<tbody>
<tr>
<td>action</td>
<td>
<ExtendedTableCode>{actionTypeString}</ExtendedTableCode>
<DxcFlex direction="column" gap="var(--spacing-gap-xs)" alignItems="baseline">
<StatusBadge status="new" />
alignment
</DxcFlex>
</td>
<td>
<TableCode>'left' | 'right'</TableCode>
</td>
<td>
Sets <Code>text-align</Code> CSS property inside the input. See{" "}
<DxcLink newWindow href="https://developer.mozilla.org/en-US/docs/Web/CSS/text-align">
MDN
</DxcLink>{" "}
for further information.
</td>
<td>
Action to be displayed on the right side of the input.
<TableCode>'left'</TableCode>
</td>
</tr>
<tr>
<td>action</td>
<td>
<ExtendedTableCode>{actionTypeString}</ExtendedTableCode>
</td>
<td>Action to be displayed on the right side of the input.</td>
<td>-</td>
</tr>
<tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,11 @@ const sections = [
<strong>Support various states consistently:</strong> reflect focus, disabled, error, and read-only states
with distinct, accessible visual cues.
</DxcBulletedList.Item>
<DxcBulletedList.Item>
<strong>Apply appropiate alignment:</strong> It is recommended to use left alignment in general, except
when there is a specific need for right alignment, such as in currency inputs or numeric fields, generally
using a suffix.
</DxcBulletedList.Item>
</DxcBulletedList>
),
},
Expand Down
11 changes: 10 additions & 1 deletion packages/lib/src/text-input/TextInput.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,16 @@ const TextInput = () => (
action={action}
/>
</ExampleContainer>
<Title title="Anatomy" theme="light" level={2} />{" "}
<Title title="Alignment" theme="light" level={2} />
<ExampleContainer>
<Title title="Alignment left" theme="light" level={4} />
<DxcTextInput label="Text input" defaultValue="Aligned text" alignment="left" />
</ExampleContainer>
<ExampleContainer>
<Title title="Alignment right" theme="light" level={4} />
<DxcTextInput label="Text input" defaultValue="Aligned text" alignment="right" />
</ExampleContainer>
<Title title="Anatomy" theme="light" level={2} />
<ExampleContainer>
<Title title="Complete example" theme="light" level={4} />
<DxcTextInput
Expand Down
7 changes: 6 additions & 1 deletion packages/lib/src/text-input/TextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ const TextInput = styled.div<{
${({ disabled, error, readOnly }) => inputStylesByState(disabled, error, readOnly)}
`;

const Input = styled.input`
const Input = styled.input<{
alignment: TextInputPropsType["alignment"];
}>`
background: none;
border: none;
outline: none;
Expand All @@ -79,6 +81,7 @@ const Input = styled.input`
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
${({ alignment }) => `text-align: ${alignment}`};

::placeholder {
color: ${({ disabled }) => (disabled ? "var(--color-fg-neutral-medium)" : "var(--color-fg-neutral-strong)")};
Expand All @@ -105,6 +108,7 @@ const AutosuggestWrapper = ({ condition, wrapper, children }: AutosuggestWrapper
const DxcTextInput = forwardRef<RefType, TextInputPropsType>(
(
{
alignment = "left",
action,
ariaLabel = "Text input",
autocomplete = "off",
Expand Down Expand Up @@ -505,6 +509,7 @@ const DxcTextInput = forwardRef<RefType, TextInputPropsType>(
</Addon>
)}
<Input
alignment={alignment}
aria-activedescendant={
hasSuggestions(suggestions) && isOpen && visualFocusIndex !== -1
? `suggestion-${visualFocusIndex}`
Expand Down
4 changes: 4 additions & 0 deletions packages/lib/src/text-input/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ type Action = {
};

type Props = {
/**
* Sets the alignment inside the input.
*/
alignment?: "left" | "right";
/**
* Text to be placed above the input. This label will be used as the aria-label attribute of the list of suggestions.
*/
Expand Down