Skip to content

Commit

Permalink
feat(InputGroup): add disabled prop
Browse files Browse the repository at this point in the history
This prop disables all nested fields.
  • Loading branch information
silvenon committed Aug 18, 2021
1 parent c7e35e1 commit 61a7f01
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 1 deletion.
16 changes: 15 additions & 1 deletion packages/orbit-components/src/InputGroup/InputGroup.stories.js
Expand Up @@ -2,7 +2,7 @@

import * as React from "react";
import { action } from "@storybook/addon-actions";
import { text, array, select } from "@storybook/addon-knobs";
import { text, array, select, boolean } from "@storybook/addon-knobs";

import InputField from "../InputField";
import Select from "../Select";
Expand Down Expand Up @@ -191,6 +191,20 @@ WithError.story = {
},
};

export const Disabled = (): React.Node => {
const disabled = boolean("Disabled", true);
return (
<InputGroup disabled={disabled} label="Disabled">
<InputField placeholder="a" maxLength={11} />
<InputField placeholder="b" maxLength={11} />
</InputGroup>
);
};

Disabled.story = {
name: "Disabled",
};

export const Playground = (): React.Node => {
const label = text("Label", "Phone number");
const flex = array("Flex", ["1 0 200px", "1 1 100%", "1 0 150px", "0 1 50%"]);
Expand Down
1 change: 1 addition & 0 deletions packages/orbit-components/src/InputGroup/README.md
Expand Up @@ -26,6 +26,7 @@ Table below contains all types of the props available in InputGroup component.
| **children** | `React.Node` | | The content of the InputGroup, normally **InputField** or **Select**. |
| dataTest | `string` | | Optional prop for testing purposes. |
| error | `React.Node` | | The error to display beneath the InputGroup. [See Functional specs](#functional-specs) |
| disabled | `boolean` | | Whether to disable all nested fields. |
| flex | `string` or `Array<string>` | `"0 1 auto"` | The flex attribute(s) for children of the InputGroup. [See Functional specs](#functional-specs) |
| help | `React.Node` | | The help to display beneath the InputGroup. |
| label | `Translation` | | The label for the InputGroup. [See Functional specs](#functional-specs) |
Expand Down
Expand Up @@ -75,4 +75,12 @@ describe("InputGroup", () => {
fireEvent.blur(input);
expect(onBlur).toHaveBeenCalled();
});
it("should be able to disable children", () => {
render(
<InputGroup disabled>
<InputField />
</InputGroup>,
);
expect(screen.getByRole("textbox")).toBeDisabled();
});
});
1 change: 1 addition & 0 deletions packages/orbit-components/src/InputGroup/index.d.ts
Expand Up @@ -17,6 +17,7 @@ interface Props extends Common.Global, Common.SpaceAfter {
readonly help?: React.ReactNode;
readonly children: React.ReactNode;
readonly error?: React.ReactNode;
readonly disabled?: boolean;
readonly onChange?: Event;
readonly onFocus?: Event;
readonly onBlur?: Event;
Expand Down
2 changes: 2 additions & 0 deletions packages/orbit-components/src/InputGroup/index.js
Expand Up @@ -172,6 +172,7 @@ const InputGroup = ({
size = SIZE_OPTIONS.NORMAL,
help,
error,
disabled,
dataTest,
spaceAfter,
onFocus,
Expand Down Expand Up @@ -241,6 +242,7 @@ const InputGroup = ({
return (
<StyledChild flex={childFlex}>
{React.cloneElement(item, {
disabled: item.props.disabled || disabled,
size,
label: undefined,
help: undefined,
Expand Down
1 change: 1 addition & 0 deletions packages/orbit-components/src/InputGroup/index.js.flow
Expand Up @@ -16,6 +16,7 @@ export type Props = {|
+help?: React.Node,
+children: React.Node,
+error?: React.Node,
+disabled?: boolean,
+onChange?: (
ev: SyntheticInputEvent<HTMLInputElement> | SyntheticInputEvent<HTMLSelectElement>,
) => void | Promise<any>,
Expand Down

0 comments on commit 61a7f01

Please sign in to comment.