Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EnhancedButton] Fix keyboard focus jumping #4127

Merged
merged 1 commit into from
Apr 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions src/FlatButton/FlatButtonLabel.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ function getStyles(props, context) {
class FlatButtonLabel extends Component {
static propTypes = {
label: PropTypes.node,
/**
* Override the inline-styles of the root element.
*/
style: PropTypes.object,
};

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why removing this description?

Copy link
Member Author

@mbrookes mbrookes Apr 30, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it there? (I'm guessing a global search-and-replace gone wrong.)

This is an internal component, so that comment doesn't appear in the docs. It doesn't add any value, just noise.

Expand Down
55 changes: 40 additions & 15 deletions src/RaisedButton/RaisedButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ class RaisedButton extends Component {

state = {
hovered: false,
keyboardFocused: false,
touched: false,
initialZDepth: 0,
zDepth: 0,
Expand All @@ -275,48 +276,72 @@ class RaisedButton extends Component {
handleMouseDown = (event) => {
// only listen to left clicks
if (event.button === 0) {
this.setState({zDepth: this.state.initialZDepth + 1});
this.setState({
zDepth: this.state.initialZDepth + 1,
});
}
if (this.props.onMouseDown) {
this.props.onMouseDown(event);
}
if (this.props.onMouseDown) this.props.onMouseDown(event);
};

handleMouseUp = (event) => {
this.setState({zDepth: this.state.initialZDepth});
if (this.props.onMouseUp) this.props.onMouseUp(event);
this.setState({
zDepth: this.state.initialZDepth,
});
if (this.props.onMouseUp) {
this.props.onMouseUp(event);
}
};

handleMouseLeave = (event) => {
if (!this.refs.container.isKeyboardFocused()) this.setState({zDepth: this.state.initialZDepth, hovered: false});
if (this.props.onMouseLeave) this.props.onMouseLeave(event);
if (!this.state.keyboardFocused) {
this.setState({
zDepth: this.state.initialZDepth,
hovered: false,
});
}
if (this.props.onMouseLeave) {
this.props.onMouseLeave(event);
}
};

handleMouseEnter = (event) => {
if (!this.refs.container.isKeyboardFocused() && !this.state.touch) {
if (!this.state.keyboardFocused && !this.state.touched) {
this.setState({hovered: true});
}
if (this.props.onMouseEnter) this.props.onMouseEnter(event);
if (this.props.onMouseEnter) {
this.props.onMouseEnter(event);
}
};

handleTouchStart = (event) => {
this.setState({
touch: true,
touched: true,
zDepth: this.state.initialZDepth + 1,
});
if (this.props.onTouchStart) this.props.onTouchStart(event);

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

handleTouchEnd = (event) => {
this.setState({zDepth: this.state.initialZDepth});
if (this.props.onTouchEnd) this.props.onTouchEnd(event);
this.setState({
zDepth: this.state.initialZDepth,
});

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

handleKeyboardFocus = (event, keyboardFocused) => {
const zDepth = keyboardFocused && !this.props.disabled ?
this.state.initialZDepth + 1 : this.state.initialZDepth;
const zDepth = (keyboardFocused && !this.props.disabled) ? this.state.initialZDepth + 1 : this.state.initialZDepth;

this.setState({
zDepth: zDepth,
keyboardFocused,
keyboardFocused: keyboardFocused,
});
};

Expand Down
1 change: 1 addition & 0 deletions src/internal/EnhancedButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ class EnhancedButton extends Component {
this.focusTimeout = setTimeout(() => {
if (tabPressed) {
this.setKeyboardFocus(event);
tabPressed = false;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the actual bug fix.

}
}, 150);

Expand Down