Просмотр исходного кода

Merge pull request #210 from smiclea/fix-confirmation

Fix `Enter` not working sometimes to confirm
Dorin Paslaru 8 лет назад
Родитель
Сommit
0fdf3fc55a
1 измененных файлов с 13 добавлено и 6 удалено
  1. 13 6
      src/components/organisms/AlertModal/index.jsx

+ 13 - 6
src/components/organisms/AlertModal/index.jsx

@@ -71,12 +71,19 @@ class AlertModal extends React.Component<Props> {
     type: 'confirmation',
   }
 
-  componentWillReceiveProps(newProps: Props) {
-    if (newProps.isOpen && !this.props.isOpen) {
-      KeyboardManager.onEnter('alert', () => { this.props.onConfirmation() }, 2)
-    } else if (!newProps.isOpen && this.props.isOpen) {
-      KeyboardManager.removeKeyDown('alert')
-    }
+  id: string
+
+  componentDidMount() {
+    this.id = new Date().getTime().toString()
+    KeyboardManager.onEnter(`alert-${this.id}`, () => {
+      if (this.props.isOpen) {
+        this.props.onConfirmation()
+      }
+    }, 2)
+  }
+
+  componentWillUnmount() {
+    KeyboardManager.removeKeyDown(`alert-${this.id}`)
   }
 
   renderDismissButton() {