]> cat aescling's git repositories - mastodon.git/commitdiff
[Glitch] Port changes to IconButton
authorThibG <thib@sitedethib.com>
Tue, 6 Aug 2019 09:59:58 +0000 (11:59 +0200)
committerThibaut Girka <thib@sitedethib.com>
Tue, 6 Aug 2019 13:09:30 +0000 (15:09 +0200)
Port changes to IconButton from 27a0d02d0d960163e98595b05412c0d03a4875d0 to glitch-soc

Signed-off-by: Thibaut Girka <thib@sitedethib.com>
app/javascript/flavours/glitch/components/icon_button.js

index 6a25794d37294ed13253de87ec0be6f3bdfffd57..c1e2f664c1756d778233ff258adbb8121523b352 100644 (file)
@@ -11,6 +11,8 @@ export default class IconButton extends React.PureComponent {
     title: PropTypes.string.isRequired,
     icon: PropTypes.string.isRequired,
     onClick: PropTypes.func,
+    onMouseDown: PropTypes.func,
+    onKeyDown: PropTypes.func,
     size: PropTypes.number,
     active: PropTypes.bool,
     pressed: PropTypes.bool,
@@ -43,6 +45,18 @@ export default class IconButton extends React.PureComponent {
     }
   }
 
+  handleMouseDown = (e) => {
+    if (!this.props.disabled && this.props.onMouseDown) {
+      this.props.onMouseDown(e);
+    }
+  }
+
+  handleKeyDown = (e) => {
+    if (!this.props.disabled && this.props.onKeyDown) {
+      this.props.onKeyDown(e);
+    }
+  }
+
   render () {
     let style = {
       fontSize: `${this.props.size}px`,
@@ -105,6 +119,8 @@ export default class IconButton extends React.PureComponent {
           title={title}
           className={classes}
           onClick={this.handleClick}
+          onMouseDown={this.handleMouseDown}
+          onKeyDown={this.handleKeyDown}
           style={style}
           tabIndex={tabIndex}
           disabled={disabled}
@@ -124,6 +140,8 @@ export default class IconButton extends React.PureComponent {
             title={title}
             className={classes}
             onClick={this.handleClick}
+            onMouseDown={this.handleMouseDown}
+            onKeyDown={this.handleKeyDown}
             style={style}
             tabIndex={tabIndex}
             disabled={disabled}