Skip to content

Commit

Permalink
fix(TableExpandHeader): fix requiredIfGivenPropExists call (#5912)
Browse files Browse the repository at this point in the history
  • Loading branch information
tw15egan authored May 2, 2020
1 parent a7e9a50 commit ff6beb3
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions packages/react/src/components/ComposedModal/ComposedModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -434,7 +434,7 @@ ModalBody.propTypes = {
/**
* Required props for the accessibility label of the header
*/
['aria-label']: requiredIfGivenPropExists(
['aria-label']: requiredIfGivenPropIsTruthy(
'hasScrollingContent',
PropTypes.string
),
Expand Down
8 changes: 4 additions & 4 deletions packages/react/src/components/DataTable/TableExpandHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 `<title>` element.
Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/components/Modal/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.`
);
Expand Down

0 comments on commit ff6beb3

Please sign in to comment.