Skip to content
This repository has been archived by the owner on Jan 13, 2023. It is now read-only.

Commit

Permalink
Short-circuit infinitely repeating alerts
Browse files Browse the repository at this point in the history
  • Loading branch information
Morgan Laco committed Oct 5, 2018
1 parent e2fe8d9 commit fcdece3
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions boilerplate/src/views/shared/text-field/text-field.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const inputStyleArray: TextStyle[] = [
borderColor: "#7fff00",
},
]
var alertWhenFocused = true

storiesOf("TextField", module)
.addDecorator(fn => <StoryScreen>{fn()}</StoryScreen>)
Expand Down Expand Up @@ -145,8 +146,14 @@ storiesOf("TextField", module)
borderRadius: 4,
borderColor: "hotpink",
}}
forwardedRef={ref => ref && ref.focus && ref.focus()}
onFocus={() => window.alert("focus")}
forwardedRef={ref => ref}
onFocus={() => {
if(alertWhenFocused) {
// Prevent text field focus from being repeatedly triggering alert
alertWhenFocused = false
window.alert("Text field focuesed with forwarded ref!")
}
}}
/>
)}
</State>
Expand Down

0 comments on commit fcdece3

Please sign in to comment.