Skip to content

Commit eb05e8e

Browse files
committed
Add props for replacing the text of buttons and labels for i18n
1 parent eb32695 commit eb05e8e

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

packages/react-core/src/components/FileUpload/FileUpload.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ export interface FileUploadProps
3636
validated?: 'success' | 'error' | 'default';
3737
/** Aria-label for the TextArea. */
3838
'aria-label'?: string;
39+
/** Placeholder string to display in the empty filename field */
40+
filenamePlaceholder?: string;
41+
/** Aria-label for the read-only filename field */
42+
filenameAriaLabel?: string;
43+
/** Text for the Browse button */
44+
browseButtonText?: string;
45+
/** Text for the Clear button */
46+
clearButtonText?: string;
3947
/** Flag to hide the TextArea. */
4048
hideTextArea?: boolean;
4149
/** Optional extra props to customize react-dropzone. */

packages/react-core/src/components/FileUpload/FileUploadField.tsx

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ export interface FileUploadFieldProps extends Omit<React.HTMLProps<HTMLFormEleme
3737
validated?: 'success' | 'error' | 'default';
3838
/** Aria-label for the TextArea. */
3939
'aria-label'?: string;
40+
/** Placeholder string to display in the empty filename field */
41+
filenamePlaceholder?: string;
42+
/** Aria-label for the read-only filename field */
43+
filenameAriaLabel?: string;
44+
/** Text for the Browse button */
45+
browseButtonText?: string;
46+
/** Text for the Clear button */
47+
clearButtonText?: string;
4048
/** Flag to hide the TextArea. Use with children to add custom support for non-text files. */
4149
hideTextArea?: boolean;
4250
/** Additional children to render after (or instead of) the TextArea. */
@@ -61,7 +69,11 @@ export const FileUploadField: React.FunctionComponent<FileUploadFieldProps> = ({
6169
isRequired = false,
6270
isDragActive = false,
6371
validated = 'default' as 'success' | 'error' | 'default',
64-
'aria-label': ariaLabel = 'File contents',
72+
'aria-label': ariaLabel = 'File upload',
73+
filenamePlaceholder = 'Drag a file here or browse to upload',
74+
filenameAriaLabel = filename ? 'Read only filename' : filenamePlaceholder,
75+
browseButtonText = 'Browse...',
76+
clearButtonText = 'Clear',
6577
containerRef = null as React.Ref<any>,
6678
children = null,
6779
hideTextArea = false,
@@ -88,16 +100,16 @@ export const FileUploadField: React.FunctionComponent<FileUploadFieldProps> = ({
88100
isDisabled={isDisabled}
89101
id={`${id}-filename`}
90102
name={`${id}-filename`}
91-
aria-label={filename ? 'Read only filename' : 'Drag a file here or browse to upload'} // TODO make this a prop for a11y
92-
placeholder="Drag a file here or browse to upload" // TODO make this a prop for a11y
103+
aria-label={filenameAriaLabel}
104+
placeholder={filenamePlaceholder}
93105
aria-describedby={`${id}-browse-button`}
94106
value={filename}
95107
/>
96108
<Button id={`${id}-browse-button`} variant={ButtonVariant.control} onClick={onBrowseButtonClick}>
97-
Browse... {/* TODO make this a prop for a11y */}
109+
{browseButtonText}
98110
</Button>
99111
<Button variant={ButtonVariant.control} isDisabled={!value} onClick={onClearButtonClick}>
100-
Clear {/* TODO make this a prop for a11y */}
112+
{clearButtonText}
101113
</Button>
102114
</InputGroup>
103115
</div>
@@ -110,7 +122,7 @@ export const FileUploadField: React.FunctionComponent<FileUploadFieldProps> = ({
110122
resizeOrientation={TextAreResizeOrientation.vertical}
111123
validated={validated}
112124
id={id}
113-
name={id} // TODO make this a prop? is it based on top-level id/name?
125+
name={id}
114126
aria-label={ariaLabel}
115127
value={value}
116128
onChange={onTextAreaChange}

0 commit comments

Comments
 (0)