Skip to content
This repository has been archived by the owner on Mar 4, 2020. It is now read-only.

fix(Popup): keypress toggle logic #304

Merged
merged 4 commits into from
Oct 3, 2018
Merged

Conversation

kuzhelov
Copy link
Contributor

@kuzhelov kuzhelov commented Oct 3, 2018

TODO

  • add entry to changelog

This PR is aimed to address #295.

The main reason for improper response of Popup's open state on key press events was the fact that for trigger component event of click was handled two times when click was initiated by key press:

  • once in onClick() handler (we need this one for controlled Popup)
  • another in PopupBehavior handler

Both these handlers were toggling open state of the Popup - and, as a result, there were no visible changes to the open state of the Popup, as two toggles resulted in open's initial value.

The core of the problem was the fact that by introducing key handlers PopupBehavior had overlapped the functionality that is already covered by browsers (specifically, specific keys handling logic). To prevent this, trigger key actions were removed from PopupBehavior - as those are not necessary: this PopupBehavior is designed to specifically target the case where button serves as a trigger (something like rather ButtonPopupBehavior) - and in that case there is no need to augment set of key handlers with space and enter keys.

@kuzhelov kuzhelov changed the title fix(Popup) keypress toggle logic fix(Popup): keypress toggle logic Oct 3, 2018
@codecov
Copy link

codecov bot commented Oct 3, 2018

Codecov Report

Merging #304 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #304   +/-   ##
=======================================
  Coverage   89.49%   89.49%           
=======================================
  Files          62       62           
  Lines        1171     1171           
  Branches      175      152   -23     
=======================================
  Hits         1048     1048           
  Misses        121      121           
  Partials        2        2

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fe60933...d611cf5. Read the comment docs.

onOpenChange={(e, newProps) => {
alert(`Popup is requested to change its open state to "${newProps.open}".`)
this.setState({ popupOpen: newProps.open })
}}
Copy link
Contributor

Choose a reason for hiding this comment

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

+1 for simplicity :)

@@ -7,7 +7,7 @@ const Types = () => (
<ExampleSection title="Types">
<ComponentExample
title="Default"
description="A default popup. Note that Popup is a controlled component, and its 'open' prop value could be changed either by parent component, or by user actions (keypress) - thus it is necessary to handle 'onOpenChanged' event. Try to press space key while button is focused to see the effect."
description="A default popup. Note that Popup is a controlled component, and its 'open' prop value could be changed either by parent component, or by user actions (e.g. key press) - thus it is necessary to handle 'onOpenChanged' event. Try to type some text into popup's input field and press ESC to see the effect."
Copy link
Contributor

Choose a reason for hiding this comment

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

like it!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants