Skip to content

Commit

Permalink
fix(tile): change expandable tile to button (#5609)
Browse files Browse the repository at this point in the history
* fix(tile): make tile button to copy accordion patter

* chore(tile): update tests
  • Loading branch information
abbeyhrt authored and Alessandra Davila committed Mar 25, 2020
1 parent 054b4f7 commit fbab6c0
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 20 deletions.
8 changes: 8 additions & 0 deletions packages/components/docs/sass.md
Original file line number Diff line number Diff line change
Expand Up @@ -22763,6 +22763,14 @@ Tile styles
}
}

.#{$prefix}--tile--expandable {
width: inherit;
color: inherit;
font-size: inherit;
text-align: left;
border: 0;
}

.#{$prefix}--tile--expandable {
overflow: hidden;
transition: max-height $duration--moderate-01 motion(standard, productive);
Expand Down
13 changes: 13 additions & 0 deletions packages/components/src/components/tile/_tile.scss
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@
}
}

// Removes Firefox automatic border on buttons
.#{$prefix}--tile--expandable::-moz-focus-inner {
border: 0;
}

.#{$prefix}--tile--clickable {
@include reset;
@include type-style('body-short-01');
Expand Down Expand Up @@ -118,6 +123,14 @@
}
}

.#{$prefix}--tile--expandable {
width: 100%;
color: inherit;
font-size: inherit;
text-align: left;
border: 0;
}

.#{$prefix}--tile--expandable {
overflow: hidden;
transition: max-height $duration--moderate-01 motion(standard, productive);
Expand Down
15 changes: 5 additions & 10 deletions packages/react/src/components/Tile/Tile-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,17 +290,14 @@ describe('Tile', () => {

// Force the expanded tile to be collapsed.
wrapper.setState({ expanded: false });
const collapsedDescription = wrapper.find('button').getElements()[0]
.props['aria-label'];
const collapsedDescription = wrapper.find('button').prop('title');
expect(collapsedDescription).toEqual(defaultCollapsedIconText);

// click on the item to expand it.
wrapper.simulate('click');

// Validate the description change
const expandedDescription = wrapper.find('button').getElements()[0].props[
'aria-label'
];
const expandedDescription = wrapper.find('button').prop('title');
expect(expandedDescription).toEqual(defaultExpandedIconText);
});

Expand All @@ -313,17 +310,15 @@ describe('Tile', () => {

// Force the expanded tile to be collapsed.
wrapper.setState({ expanded: false });
const collapsedDescription = wrapper.find('button').getElements()[0]
.props['aria-label'];
const collapsedDescription = wrapper.find('button').prop('title');

expect(collapsedDescription).toEqual(tileCollapsedIconText);

// click on the item to expand it.
wrapper.simulate('click');

// Validate the description change
const expandedDescription = wrapper.find('button').getElements()[0].props[
'aria-label'
];
const expandedDescription = wrapper.find('button').prop('title');
expect(expandedDescription).toEqual(tileExpandedIconText);
});

Expand Down
16 changes: 6 additions & 10 deletions packages/react/src/components/Tile/Tile.js
Original file line number Diff line number Diff line change
Expand Up @@ -542,15 +542,16 @@ export class ExpandableTile extends Component {

return (
// eslint-disable-next-line jsx-a11y/click-events-have-key-events,jsx-a11y/no-static-element-interactions
<div
<button
ref={tile => {
this.tile = tile;
}}
style={tileStyle}
className={classes}
aria-expanded={isExpanded}
title={isExpanded ? tileExpandedIconText : tileCollapsedIconText}
{...other}
onClick={this.handleClick}
onKeyPress={this.handleKeyDown}
tabIndex={tabIndex}>
<div
ref={tileContent => {
Expand All @@ -563,17 +564,12 @@ export class ExpandableTile extends Component {
className={`${prefix}--tile-content`}>
{childrenAsArray[0]}
</div>
<button
aria-expanded={isExpanded}
aria-label={
isExpanded ? tileExpandedIconText : tileCollapsedIconText
}
className={`${prefix}--tile__chevron`}>
<div className={`${prefix}--tile__chevron`}>
<ChevronDown16 />
</button>
</div>
<div className={`${prefix}--tile-content`}>{childrenAsArray[1]}</div>
</div>
</div>
</button>
);
}
}
Expand Down

0 comments on commit fbab6c0

Please sign in to comment.