Skip to content

Commit

Permalink
let's merge
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Nov 13, 2018
1 parent 02a442d commit 0217583
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,24 @@ class ExpansionPanelSummary extends React.Component {
focused: false,
};

handleFocus = () => {
handleFocusVisible = event => {
this.setState({
focused: true,
});

if (this.props.onFocusVisible) {
this.props.onFocusVisible(event);
}
};

handleBlur = () => {
handleBlur = event => {
this.setState({
focused: false,
});
if (typeof this.props.onBlur === 'function') this.props.onBlur();

if (this.props.onBlur) {
this.props.onBlur(event);
}
};

handleChange = event => {
Expand All @@ -107,7 +114,10 @@ class ExpansionPanelSummary extends React.Component {
expanded,
expandIcon,
IconButtonProps,
onBlur,
onChange,
onClick,
onFocusVisible,
...other
} = this.props;
const { focused } = this.state;
Expand All @@ -128,10 +138,10 @@ class ExpansionPanelSummary extends React.Component {
},
className,
)}
{...other}
onFocusVisible={this.handleFocus}
onFocusVisible={this.handleFocusVisible}
onBlur={this.handleBlur}
onClick={this.handleChange}
{...other}
>
<div className={classNames(classes.content, { [classes.expanded]: expanded })}>
{children}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,26 @@ describe('<ExpansionPanelSummary />', () => {
assert.strictEqual(wrapper.state().focused, false);
});

describe('prop: onBlur', () => {
it('handleblur should call onBlur prop when focus leaves', () => {
const myOnBlur = spy();
const wrapper = mount(<ExpansionPanelSummaryNaked onBlur={myOnBlur} classes={{}} />);
wrapper.instance().handleBlur();
assert.strictEqual(myOnBlur.callCount, 1, 'should have been called once');
describe('event callbacks', () => {
it('should fire event callbacks', () => {
const events = [
'onClick',
'onFocusVisible',
'onBlur',
];

const handlers = events.reduce((result, n) => {
result[n] = spy();
return result;
}, {});

const wrapper = shallow(<ExpansionPanelSummary {...handlers} />);

events.forEach(n => {
const event = n.charAt(2).toLowerCase() + n.slice(3);
wrapper.simulate(event, { persist: () => {} });
assert.strictEqual(handlers[n].callCount, 1, `should have called the ${n} handler`);
});
});
});

Expand Down

0 comments on commit 0217583

Please sign in to comment.