Skip to content

Commit d3072fc

Browse files
committed
feat(InputFile): add required labelRemove prop
BREAKING CHANGE: The InputFile component now has a required labelRemove prop.
1 parent 152a0f7 commit d3072fc

File tree

5 files changed

+21
-6
lines changed

5 files changed

+21
-6
lines changed

packages/orbit-components/src/InputFile/InputFile.stories.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export const Default: Story = {};
3434
export const FilledWithFile: Story = {
3535
args: {
3636
fileName: "file.png",
37+
labelRemove: "Remove file",
3738
},
3839
};
3940

packages/orbit-components/src/InputFile/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import InputFile from "@kiwicom/orbit-components/lib/InputFile";
99
After adding import into your project you can use it simply like:
1010

1111
```jsx
12-
<InputFile />
12+
<InputFile labelRemove="Remove file" />
1313
```
1414

1515
## Props
@@ -40,6 +40,7 @@ Table below contains all types of the props available in the InputFile component
4040
| insideInputGroup | `boolean` | `false` | Set to `true` if InputFile is inside InputGroup |
4141
| multiple | `boolean` | | If set to `true` will allow to upload multiple files |
4242
| disabled | `boolean` | | If set to `true` will allow to upload multiple files |
43+
| labelRemove | `string` | | Required label for the remove file button. |
4344

4445
### enum
4546

packages/orbit-components/src/InputFile/__tests__/index.test.tsx

+15-4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ describe("InputFile", () => {
1111
it("should have expected DOM output", async () => {
1212
const label = "Select file";
1313
const buttonLabel = "Click on me";
14+
const labelRemove = "Remove file";
1415
const name = "name";
1516
const placeholder = "Not file has been selected";
1617
const dataTest = "test";
@@ -34,6 +35,7 @@ describe("InputFile", () => {
3435
tabIndex={tabIndex}
3536
onChange={onChange}
3637
onFocus={onFocus}
38+
labelRemove={labelRemove}
3739
/>,
3840
);
3941

@@ -55,7 +57,15 @@ describe("InputFile", () => {
5557
const onChange = jest.fn();
5658
const onFocus = jest.fn();
5759

58-
render(<InputFile dataTest="test" disabled onChange={onChange} onFocus={onFocus} />);
60+
render(
61+
<InputFile
62+
dataTest="test"
63+
disabled
64+
onChange={onChange}
65+
onFocus={onFocus}
66+
labelRemove="Remove file"
67+
/>,
68+
);
5969

6070
const input = screen.getByTestId("test");
6171
expect(input).toBeDisabled();
@@ -66,16 +76,16 @@ describe("InputFile", () => {
6676

6777
it("should have passed width", () => {
6878
const width = "100px";
69-
render(<InputFile width={width} label="label" />);
79+
render(<InputFile width={width} label="label" labelRemove="Remove file" />);
7080
expect(document.querySelector("label")).toHaveStyle({ width });
7181
});
7282

7383
it("should have filename, onRemoveFile", async () => {
7484
const onRemoveFile = jest.fn();
7585

76-
render(<InputFile fileName="bur" onRemoveFile={onRemoveFile} />);
86+
render(<InputFile fileName="bur" onRemoveFile={onRemoveFile} labelRemove="Remove file" />);
7787

78-
const button = screen.getByRole("button", { name: "remove" });
88+
const button = screen.getByRole("button", { name: "Remove file" });
7989
await user.click(button);
8090
expect(onRemoveFile).toHaveBeenCalled();
8191
});
@@ -89,6 +99,7 @@ describe("InputFile", () => {
8999
onFocus={onFocus}
90100
onBlur={onBlur}
91101
error="chuck norris counted to infinity twice"
102+
labelRemove="Remove file"
92103
/>,
93104
);
94105

packages/orbit-components/src/InputFile/index.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const InputFile = React.forwardRef<HTMLDivElement, Props>((props, ref) => {
3737
tabIndex,
3838
fileName,
3939
insideInputGroup,
40+
labelRemove,
4041
} = props;
4142

4243
const hasTooltip = Boolean(error || help);
@@ -141,7 +142,7 @@ const InputFile = React.forwardRef<HTMLDivElement, Props>((props, ref) => {
141142
type="primary"
142143
disabled={disabled}
143144
compact
144-
iconLeft={<CloseCircle ariaLabel="remove" color="secondary" />}
145+
iconLeft={<CloseCircle ariaLabel={labelRemove} color="secondary" />}
145146
onClick={ev => {
146147
ev.preventDefault();
147148
if (onRemoveFile) {

packages/orbit-components/src/InputFile/types.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@ export interface Props extends Common.Globals, Common.SpaceAfter {
2424
readonly insideInputGroup?: boolean;
2525
readonly onRemoveFile?: Common.Callback;
2626
readonly multiple?: boolean;
27+
readonly labelRemove: string;
2728
}

0 commit comments

Comments
 (0)