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

feat(react): added disabled prop to file uploader #10613

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -2587,6 +2587,7 @@ Map {
"accept": Array [],
"buttonKind": "primary",
"buttonLabel": "",
"disabled": false,
"filenameStatus": "uploading",
"iconDescription": "Provide icon description",
"multiple": false,
Expand Down Expand Up @@ -2622,6 +2623,9 @@ Map {
"className": Object {
"type": "string",
},
"disabled": Object {
"type": "bool",
},
"filenameStatus": Object {
"args": Array [
Array [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ const props = {
),
buttonLabel: text('The button label (buttonLabel)', 'Add file'),
buttonKind: buttonKind || 'primary',
disabled: boolean('Disabled (disabled)', false),
tay1orjones marked this conversation as resolved.
Show resolved Hide resolved
size: select('Button size (size)', sizes, 'default'),
filenameStatus: select(
'Status for file name (filenameStatus)',
Expand Down
21 changes: 19 additions & 2 deletions packages/react/src/components/FileUploader/FileUploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ export default class FileUploader extends React.Component {
*/
className: PropTypes.string,

/**
* Specify whether file input is disabled
*/
disabled: PropTypes.bool,

/**
* Specify the status of the File Upload
*/
Expand Down Expand Up @@ -100,6 +105,7 @@ export default class FileUploader extends React.Component {
static contextType = PrefixContext;

static defaultProps = {
disabled: false,
iconDescription: FeatureFlags.enabled('enable-v11-release')
? undefined
: 'Provide icon description',
Expand Down Expand Up @@ -167,6 +173,7 @@ export default class FileUploader extends React.Component {
iconDescription,
buttonLabel,
buttonKind,
disabled,
filenameStatus,
labelDescription,
labelTitle,
Expand All @@ -186,6 +193,11 @@ export default class FileUploader extends React.Component {
[className]: className,
});

const getHelperLabelClasses = (baseClass) =>
classNames(baseClass, {
[`${prefix}--label-description--disabled`]: disabled,
});

const selectedFileClasses = classNames(`${prefix}--file__selected-file`, {
[`${prefix}--file__selected-file--md`]: size === 'field' || size === 'md',
[`${prefix}--file__selected-file--sm`]: size === 'small' || size === 'sm',
Expand All @@ -194,10 +206,15 @@ export default class FileUploader extends React.Component {
return (
<div className={classes} {...other}>
{FeatureFlags.enabled('enable-v11-release') && !labelTitle ? null : (
<p className={`${prefix}--file--label`}>{labelTitle}</p>
<p className={getHelperLabelClasses(`${prefix}--file--label`)}>
{labelTitle}
</p>
)}
<p className={`${prefix}--label-description`}>{labelDescription}</p>
<p className={getHelperLabelClasses(`${prefix}--label-description`)}>
{labelDescription}
</p>
<FileUploaderButton
disabled={disabled}
labelText={buttonLabel}
multiple={multiple}
buttonKind={buttonKind}
Expand Down