From 6819870bb8229ef43f94cc514dc0a339e8aef279 Mon Sep 17 00:00:00 2001 From: Tom Nunn Date: Fri, 1 Jul 2022 15:44:28 +0200 Subject: [PATCH] Add isMenuPlacementAbove --- src/Internal/Model.elm | 48 +++++++++++++++++++++--------------------- src/Select.elm | 13 ++++++++++-- 2 files changed, 35 insertions(+), 26 deletions(-) diff --git a/src/Internal/Model.elm b/src/Internal/Model.elm index e34a1e3..0dd4e0b 100644 --- a/src/Internal/Model.elm +++ b/src/Internal/Model.elm @@ -161,30 +161,6 @@ toOptionState (Model { highlighted, selected }) ( idx, a ) = Idle - --- CHECKS - - -isOpen : Model a -> Bool -isOpen (Model { menuOpen }) = - menuOpen - - -isFocused : Model a -> Bool -isFocused (Model { focused }) = - focused - - -isLoading : Model a -> Bool -isLoading (Model { requestState }) = - requestState == Just Loading - - -isRequestFailed : Model a -> Bool -isRequestFailed (Model { requestState }) = - requestState == Just Failed - - toMenuPlacement : Maybe Placement -> Model a -> Placement toMenuPlacement forcedPlacement (Model model) = Maybe.map2 (calculateMenuDimensionsAndPlacement forcedPlacement) model.containerElement model.menuElement @@ -210,6 +186,30 @@ toContainerElement (Model { containerElement }) = +-- CHECKS + + +isOpen : Model a -> Bool +isOpen (Model { menuOpen }) = + menuOpen + + +isFocused : Model a -> Bool +isFocused (Model { focused }) = + focused + + +isLoading : Model a -> Bool +isLoading (Model { requestState }) = + requestState == Just Loading + + +isRequestFailed : Model a -> Bool +isRequestFailed (Model { requestState }) = + requestState == Just Failed + + + -- UPDATE diff --git a/src/Select.elm b/src/Select.elm index 8da4def..9da6bd5 100644 --- a/src/Select.elm +++ b/src/Select.elm @@ -2,7 +2,7 @@ module Select exposing ( Select, init , setItems, setSelected, setInputValue, closeMenu , toValue, toInputValue - , isMenuOpen, isLoading, isRequestFailed + , isMenuOpen, isLoading, isRequestFailed, isMenuPlacementAbove , Msg, update, updateWithRequest, Request, request, gotRequestResponse , ViewConfig, view, withMenuAttributes, withMenuMaxHeight, withMenuMaxWidth, withNoMatchElement, OptionState, withOptionElement, ClearButton, withClearButton, clearButton, withFilter, withMenuAlwaysAbove, withMenuAlwaysBelow, withMenuPositionFixed , toElement @@ -29,7 +29,7 @@ module Select exposing # Check -@docs isMenuOpen, isLoading, isRequestFailed +@docs isMenuOpen, isLoading, isRequestFailed, isMenuPlacementAbove # Update and Requests @@ -154,6 +154,15 @@ isRequestFailed = Model.isRequestFailed +{-| Will the menu appear above the input as opposed to below? +Note: This does not take into account overriding placement with +[Select.withMenuAlwaysAbove](#withMenuAlwaysAbove) or [Select.withMenuAlwaysBelow](#withMenuAlwaysAbove). +-} +isMenuPlacementAbove : Select a -> Bool +isMenuPlacementAbove = + Model.toMenuPlacement Nothing >> (==) Above + + -- UPDATE