Skip to content

Commit

Permalink
feat(Text): add text to Accordion, Button, Checkbox, Combobox, Conten…
Browse files Browse the repository at this point in the history
…tswitcher (#9493)

* feat(Text): add Text to Accordion, Button, Checkbox, Combobox, Switcher

* test(Text): update snapshots

* fix(Accordion, Button): revert changes as per pr review

* test(Accordion): update snappies

* fix(ContentSwitcher): revert changes to text prop

* fix(accordion-item): wrap title in text instead of children

* test: update snapshots

Co-authored-by: Taylor Jones <taylor.jones826@gmail.com>
Co-authored-by: Taylor Jones <tay1orjones@users.noreply.github.com>
  • Loading branch information
3 people authored Sep 20, 2021
1 parent 1254da5 commit b5c1f82
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 9 deletions.
5 changes: 4 additions & 1 deletion packages/react/src/components/Accordion/AccordionItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { settings } from 'carbon-components';
import cx from 'classnames';
import PropTypes from 'prop-types';
import React, { useState } from 'react';
import { Text } from '../Text';
import { match, keys } from '../../internal/keyboard';
import { useId } from '../../internal/useId';
import deprecate from '../../prop-types/deprecate.js';
Expand Down Expand Up @@ -84,7 +85,9 @@ function AccordionItem({
onKeyDown={onKeyDown}
type="button">
<ChevronRight16 className={`${prefix}--accordion__arrow`} />
<div className={`${prefix}--accordion__title`}>{title}</div>
<Text as="div" className={`${prefix}--accordion__title`}>
{title}
</Text>
</Expando>
<div id={id} className={`${prefix}--accordion__content`}>
{children}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ exports[`Accordion should render 1`] = `
</svg>
<div
class="bx--accordion__title"
dir="auto"
>
Heading A
</div>
Expand Down Expand Up @@ -68,6 +69,7 @@ exports[`Accordion should render 1`] = `
</svg>
<div
class="bx--accordion__title"
dir="auto"
>
Heading B
</div>
Expand Down Expand Up @@ -105,6 +107,7 @@ exports[`Accordion should render 1`] = `
</svg>
<div
class="bx--accordion__title"
dir="auto"
>
Heading C
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,17 @@ exports[`AccordionItem should render 1`] = `
</svg>
</Icon>
</ForwardRef(ChevronRight16)>
<div
<Text
as="div"
className="bx--accordion__title"
>
A heading
</div>
<div
className="bx--accordion__title"
dir="auto"
>
A heading
</div>
</Text>
</button>
</defaultRenderExpando>
<div
Expand Down
1 change: 1 addition & 0 deletions packages/react/src/components/Button/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ const Button = React.forwardRef(function Button(
component = 'a';
otherProps = anchorProps;
}

return React.createElement(
component,
{
Expand Down
3 changes: 2 additions & 1 deletion packages/react/src/components/Checkbox/Checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import PropTypes from 'prop-types';
import React from 'react';
import classNames from 'classnames';
import { Text } from '../Text';
import { useFeatureFlag } from '../FeatureFlags';
import { settings } from 'carbon-components';
import deprecate from '../../prop-types/deprecate';
Expand Down Expand Up @@ -69,7 +70,7 @@ const Checkbox = React.forwardRef(function Checkbox(
}}
/>
<label htmlFor={id} className={labelClasses} title={title || null}>
<span className={innerLabelClasses}>{labelText}</span>
<Text className={innerLabelClasses}>{labelText}</Text>
</label>
</div>
);
Expand Down
9 changes: 5 additions & 4 deletions packages/react/src/components/ComboBox/ComboBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import cx from 'classnames';
import Downshift from 'downshift';
import PropTypes from 'prop-types';
import React, { useEffect, useState, useRef } from 'react';
import { Text } from '../Text';
import { settings } from 'carbon-components';
import {
Checkmark16,
Expand Down Expand Up @@ -293,9 +294,9 @@ const ComboBox = React.forwardRef((props, ref) => {
return (
<div className={wrapperClasses}>
{titleText && (
<label className={titleClasses} {...labelProps}>
<Text as="label" className={titleClasses} {...labelProps}>
{titleText}
</label>
</Text>
)}
<ListBox
className={className}
Expand Down Expand Up @@ -391,9 +392,9 @@ const ComboBox = React.forwardRef((props, ref) => {
</ListBox.Menu>
</ListBox>
{helperText && !invalid && !warn && (
<div id={comboBoxHelperId} className={helperClasses}>
<Text as="div" id={comboBoxHelperId} className={helperClasses}>
{helperText}
</div>
</Text>
)}
</div>
);
Expand Down

0 comments on commit b5c1f82

Please sign in to comment.