From 8973b5988f01b7ea56910a810f785867fd3a674e Mon Sep 17 00:00:00 2001 From: Daniel Acosta Date: Tue, 25 Jun 2019 15:29:59 -0500 Subject: [PATCH 1/3] Prevent rerender when a button callback returns false. --- addons/knobs/src/registerKnobs.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/addons/knobs/src/registerKnobs.js b/addons/knobs/src/registerKnobs.js index 412783c36249..40b98b223d9b 100644 --- a/addons/knobs/src/registerKnobs.js +++ b/addons/knobs/src/registerKnobs.js @@ -44,8 +44,9 @@ function knobChanged(change) { function knobClicked(clicked) { const knobOptions = knobStore.get(clicked.name); - knobOptions.callback(); - forceReRender(); + if (knobOptions.callback()!==false) { + forceReRender(); + } } function resetKnobs() { From 8ea2b06a204cc1b6dfd01d6a1f7f9e705167e8c3 Mon Sep 17 00:00:00 2001 From: Daniel Acosta Date: Tue, 25 Jun 2019 15:36:53 -0500 Subject: [PATCH 2/3] Update knobs docs. --- addons/knobs/README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/addons/knobs/README.md b/addons/knobs/README.md index 23c0a28cc05d..c66c8c79fa6e 100644 --- a/addons/knobs/README.md +++ b/addons/knobs/README.md @@ -410,6 +410,9 @@ const groupId = 'GROUP-ID1'; button(label, handler, groupId); ``` +Button knobs cause the story to re-render after the handler fires, you can prevent +this by having the handler return false. + ### withKnobs options withKnobs also accepts two optional options as story parameters. From e7cf084d06a974a58f0f420a5a3686b0c67be621 Mon Sep 17 00:00:00 2001 From: Daniel Acosta Date: Wed, 26 Jun 2019 09:25:22 -0500 Subject: [PATCH 3/3] Prevent rerender when a button callback returns false. (lint fix) Co-Authored-By: Wei-Wei Wu --- addons/knobs/src/registerKnobs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/knobs/src/registerKnobs.js b/addons/knobs/src/registerKnobs.js index 40b98b223d9b..07e3ecf08d73 100644 --- a/addons/knobs/src/registerKnobs.js +++ b/addons/knobs/src/registerKnobs.js @@ -44,7 +44,7 @@ function knobChanged(change) { function knobClicked(clicked) { const knobOptions = knobStore.get(clicked.name); - if (knobOptions.callback()!==false) { + if (knobOptions.callback() !== false) { forceReRender(); } }