From ff6beb3e4d681d2f70d1b2256d3a6edef94cac33 Mon Sep 17 00:00:00 2001 From: TJ Egan Date: Fri, 1 May 2020 17:31:21 -0700 Subject: [PATCH] fix(TableExpandHeader): fix requiredIfGivenPropExists call (#5912) --- .../react/src/components/ComposedModal/ComposedModal.js | 4 ++-- .../react/src/components/DataTable/TableExpandHeader.js | 8 ++++---- packages/react/src/components/Modal/Modal.js | 4 ++-- ...fGivenPropExists.js => requiredIfGivenPropIsTruthy.js} | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) rename packages/react/src/prop-types/{requiredIfGivenPropExists.js => requiredIfGivenPropIsTruthy.js} (84%) diff --git a/packages/react/src/components/ComposedModal/ComposedModal.js b/packages/react/src/components/ComposedModal/ComposedModal.js index e25a1283d482..8ce366d6b032 100644 --- a/packages/react/src/components/ComposedModal/ComposedModal.js +++ b/packages/react/src/components/ComposedModal/ComposedModal.js @@ -12,7 +12,7 @@ import classNames from 'classnames'; import { settings } from 'carbon-components'; import { Close20 } from '@carbon/icons-react'; import toggleClass from '../../tools/toggleClass'; -import requiredIfGivenPropExists from '../../prop-types/requiredIfGivenPropExists'; +import requiredIfGivenPropIsTruthy from '../../prop-types/requiredIfGivenPropIsTruthy'; import wrapFocus from '../../internal/wrapFocus'; const { prefix } = settings; @@ -434,7 +434,7 @@ ModalBody.propTypes = { /** * Required props for the accessibility label of the header */ - ['aria-label']: requiredIfGivenPropExists( + ['aria-label']: requiredIfGivenPropIsTruthy( 'hasScrollingContent', PropTypes.string ), diff --git a/packages/react/src/components/DataTable/TableExpandHeader.js b/packages/react/src/components/DataTable/TableExpandHeader.js index 482682e8078a..a1f37d6d0550 100644 --- a/packages/react/src/components/DataTable/TableExpandHeader.js +++ b/packages/react/src/components/DataTable/TableExpandHeader.js @@ -7,7 +7,7 @@ import cx from 'classnames'; import PropTypes from 'prop-types'; -import requiredIfGivenPropExists from '../../prop-types/requiredIfGivenPropExists'; +import requiredIfGivenPropIsTruthy from '../../prop-types/requiredIfGivenPropIsTruthy'; import React from 'react'; import { ChevronRight16 } from '@carbon/icons-react'; import { settings } from 'carbon-components'; @@ -58,18 +58,18 @@ TableExpandHeader.propTypes = { * Specify the string read by a voice reader when the expand trigger is * focused */ - ariaLabel: requiredIfGivenPropExists('enableExpando', PropTypes.string), + ariaLabel: requiredIfGivenPropIsTruthy('enableExpando', PropTypes.string), /** * Specify whether this row is expanded or not. This helps coordinate data * attributes so that `TableExpandRow` and `TableExapndedRow` work together */ - isExpanded: requiredIfGivenPropExists('enableExpando', PropTypes.bool), + isExpanded: requiredIfGivenPropIsTruthy('enableExpando', PropTypes.bool), /** * Hook for when a listener initiates a request to expand the given row */ - onExpand: requiredIfGivenPropExists('enableExpando', PropTypes.func), + onExpand: requiredIfGivenPropIsTruthy('enableExpando', PropTypes.func), /** * The description of the chevron right icon, to be put in its SVG `` element. diff --git a/packages/react/src/components/Modal/Modal.js b/packages/react/src/components/Modal/Modal.js index dd7a1a2e501e..a129fe171316 100644 --- a/packages/react/src/components/Modal/Modal.js +++ b/packages/react/src/components/Modal/Modal.js @@ -13,7 +13,7 @@ import { Close20 } from '@carbon/icons-react'; import toggleClass from '../../tools/toggleClass'; import Button from '../Button'; import deprecate from '../../prop-types/deprecate'; -import requiredIfGivenPropExists from '../../prop-types/requiredIfGivenPropExists'; +import requiredIfGivenPropIsTruthy from '../../prop-types/requiredIfGivenPropIsTruthy'; import wrapFocus, { elementOrParentIsFloatingMenu, } from '../../internal/wrapFocus'; @@ -157,7 +157,7 @@ export default class Modal extends Component { /** * Required props for the accessibility label of the header */ - ['aria-label']: requiredIfGivenPropExists( + ['aria-label']: requiredIfGivenPropIsTruthy( 'hasScrollingContent', PropTypes.string ), diff --git a/packages/react/src/prop-types/requiredIfGivenPropExists.js b/packages/react/src/prop-types/requiredIfGivenPropIsTruthy.js similarity index 84% rename from packages/react/src/prop-types/requiredIfGivenPropExists.js rename to packages/react/src/prop-types/requiredIfGivenPropIsTruthy.js index 355481920fc2..3ed79dd49b8d 100644 --- a/packages/react/src/prop-types/requiredIfGivenPropExists.js +++ b/packages/react/src/prop-types/requiredIfGivenPropIsTruthy.js @@ -12,9 +12,9 @@ * @returns {Function} The new prop type checker for the current prop that * becomes required if the prop corresponding to the provided prop name exists. */ -export default function requiredIfGivenPropExists(name, propType) { +export default function requiredIfGivenPropIsTruthy(name, propType) { return function check(props, propName, componentName, ...rest) { - if (__DEV__ && props[name]) { + if (__DEV__ && props[name] == true && props[propName] == null) { return new Error( `You must provide a value for \`${propName}\` in \`${componentName}\` if \`${name}\` exists.` );