Skip to content

Commit 18f337b

Browse files
committed
[code commentary] regarding use of mousedown instead of click for opening the dropdown menu
1 parent 17af183 commit 18f337b

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/ReactSelectize.ls

+7-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ module.exports = create-class do
108108
class-name: class-name-from-object do
109109
\react-selectize : 1
110110
"#{@props.theme}" : 1
111-
\control-wrapper : 1
112111
\root-node : 1
113112
"#{@props.class-name}" : 1
114113
disabled: @props.disabled
@@ -130,12 +129,19 @@ module.exports = create-class do
130129
div do
131130
class-name: \react-selectize-control
132131
ref: \control
132+
133+
# using click would cause a flicker because:
134+
# 1: on mouse down, the focus will blur from the search field causing the dropdown menu to close
135+
# 2: on mouse up, the click event will be fired and open the dropdown menu again
136+
# on mouse down, we have to cancel the event otherwise the search field would cause the same problem above
133137
on-mouse-down: (e) ~>
134138
do ~>
135139
<~ @props.on-anchor-change last @props.values
136140
<~ @on-open-change true
137141
@highlight-and-focus!
138142

143+
# avoid cancelling the event when the dropdown is already open
144+
# as this would block selection of text in the search field
139145
if !@props.open
140146
cancel-event e
141147

0 commit comments

Comments
 (0)