Skip to content

Commit 3a2f5ad

Browse files
committed
moved dropdown-direction code to DropdownMenu component (added bottom-anchor prop)
1 parent e38b7b4 commit 3a2f5ad

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

src/DropdownMenu.ls

+9-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ module.exports = create-class do
1616

1717
# get-default-props :: () -> Props
1818
get-default-props: ->
19+
# bottom-anchor :: () -> ReactElement
1920
class-name: ""
2021
dropdown-direction: 1
2122
group-id: (.group-id) # Item -> a
@@ -86,7 +87,7 @@ module.exports = create-class do
8687
if !!@props.transition-enter or !!@props.transition-leave
8788
ReactCSSTransitionGroup do
8889
component: \div
89-
transition-name: \slide
90+
transition-name: \custom
9091
transition-enter: @props.transition-enter
9192
transition-leave: @props.transition-leave
9293
transition-enter-timeout: @props.transition-enter-timeout
@@ -181,6 +182,13 @@ module.exports = create-class do
181182
else
182183
null
183184

185+
# component-did-update :: () -> ()
186+
component-did-update: !->
187+
dropdown-menu = find-DOM-node @refs.dropdown-menu-container ? @refs.dropdown-menu
188+
..?style.bottom = switch
189+
| @props.dropdown-direction == -1 => @props.bottom-anchor!.offset-height + dropdown-menu.style.margin-bottom
190+
| _ => ""
191+
184192
# highlight-and-scroll-to-option :: Int, (() -> ())? -> ()
185193
highlight-and-scroll-to-option: (index, callback = (->)) !->
186194

src/ReactSelectize.ls

+10-12
Original file line numberDiff line numberDiff line change
@@ -226,26 +226,29 @@ module.exports = create-class do
226226

227227
# (TETHERED / ANIMATED / SIMPLE) DROPDOWN
228228
DropdownMenu {} <<< @props <<<
229-
230229
ref: \dropdownMenu
231-
232230
class-name: class-name-from-object do
233231
\react-selectize : 1
234232
"#{@props.class-name}" : 1
235-
236233
theme: @props.theme
237234

238-
# on-option-click :: (Eq e) => e -> ()
239-
on-option-click: (highlighted-uid) !~>
240-
<~ @select-highlighted-uid anchor-index
241-
235+
# scroll-lock is used for blocking mouse interference with highlighted uid when using the arrow keys
236+
# to scroll through the options list
242237
scroll-lock: @props.scroll-lock
243238
on-scroll-change: @props.on-scroll-change
244239

240+
# used when dropdown-direction is -1
241+
# bottom-anchor :: () -> ReactElement
242+
bottom-anchor: ~> find-DOM-node @refs.control
243+
245244
# used when @props.tether is true
246245
# tether-target :: () -> ReactElement
247246
tether-target: ~> find-DOM-node @refs.control
248247

248+
# on-option-click :: (Eq e) => e -> ()
249+
on-option-click: (highlighted-uid) !~>
250+
<~ @select-highlighted-uid anchor-index
251+
249252

250253
# handle-keydown :: ComputedState -> Event -> Boolean
251254
handle-keydown: ({anchor-index}, e) ->
@@ -393,11 +396,6 @@ module.exports = create-class do
393396
if !@props.open and prev-props.open
394397
@props.on-highlighted-uid-change undefined
395398

396-
# flip the dropdown if props.dropdown-direction is -1
397-
if @refs.dropdown-menu
398-
(find-DOM-node @refs.dropdown-menu)?.style <<<
399-
bottom: if @props.dropdown-direction == -1 then (find-DOM-node @refs.control).offset-height else ""
400-
401399
# component-will-receive-props :: Props -> ()
402400
component-will-receive-props: (props) !->
403401
if (typeof @props.disabled == \undefined or @props.disabled == false) and

0 commit comments

Comments
 (0)