From c3deec41d7f7c7cbd388df456bc9a3c1ded5a680 Mon Sep 17 00:00:00 2001 From: futpib Date: Wed, 14 Nov 2018 05:37:09 +0300 Subject: [PATCH] Fix focus stealing --- components/button/index.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/components/button/index.js b/components/button/index.js index ae46d45..d0c420f 100644 --- a/components/button/index.js +++ b/components/button/index.js @@ -1,12 +1,18 @@ +const { + memoizeWith, +} = require('ramda'); + const r = require('r-dom'); +const ref = memoizeWith(autoFocus => String(Boolean(autoFocus)), autoFocus => input => { + if (input && autoFocus) { + input.focus(); + } +}); + const Button = props => r.button({ - ref: input => { - if (input && props.autoFocus) { - input.focus(); - } - }, + ref, className: 'button', ...props, }, props.children);