diff --git a/src/Internal/Effect.elm b/src/Internal/Effect.elm index 4881ad8..47dd2fb 100644 --- a/src/Internal/Effect.elm +++ b/src/Internal/Effect.elm @@ -1,6 +1,6 @@ module Internal.Effect exposing (Effect(..), batch, none, perform) -import Browser.Dom as Dom exposing (Element) +import Browser.Dom as Dom import Internal.Msg exposing (Msg(..)) import Process import Task exposing (Task) @@ -49,7 +49,7 @@ perform tagger requestCmd effect = Cmd.none -getContainerAndMenuElements : (Result Dom.Error { menu : Element, container : Element } -> msg) -> { containerId : String, menuId : String } -> Cmd msg +getContainerAndMenuElements : (Result Dom.Error { menu : Dom.Viewport, container : Dom.Element } -> msg) -> { containerId : String, menuId : String } -> Cmd msg getContainerAndMenuElements msg { containerId, menuId } = Task.map2 (\container menu -> @@ -58,7 +58,7 @@ getContainerAndMenuElements msg { containerId, menuId } = } ) (Dom.getElement containerId) - (Dom.getElement menuId) + (Dom.getViewportOf menuId) |> Task.attempt msg diff --git a/src/Internal/Model.elm b/src/Internal/Model.elm index 1b52a1a..604518e 100644 --- a/src/Internal/Model.elm +++ b/src/Internal/Model.elm @@ -58,7 +58,7 @@ type alias InternalState a = , highlighted : Int , menuOpen : Bool , containerElement : Maybe Dom.Element - , menuElement : Maybe Dom.Element + , menuViewPort : Maybe Dom.Viewport , requestState : Maybe RequestState , applyFilter : Bool , focused : Bool @@ -79,7 +79,7 @@ init id = , highlighted = 0 , menuOpen = False , containerElement = Nothing - , menuElement = Nothing + , menuViewPort = Nothing , requestState = Nothing , applyFilter = False , focused = False @@ -163,20 +163,20 @@ toOptionState (Model { highlighted, selected }) ( idx, a ) = toMenuPlacement : Maybe Int -> Maybe Placement -> Model a -> Placement toMenuPlacement maxHeight forcedPlacement (Model model) = - Maybe.map2 (calculateMenuDimensionsAndPlacement maxHeight forcedPlacement) model.containerElement model.menuElement + Maybe.map2 (calculateMenuDimensionsAndPlacement maxHeight forcedPlacement) model.containerElement model.menuViewPort |> Maybe.map .placement |> Maybe.withDefault Below toMenuMinWidth : Model a -> Maybe Int toMenuMinWidth (Model model) = - Maybe.map2 (calculateMenuDimensionsAndPlacement Nothing Nothing) model.containerElement model.menuElement + Maybe.map2 (calculateMenuDimensionsAndPlacement Nothing Nothing) model.containerElement model.menuViewPort |> Maybe.map .minWidth toMenuMaxHeight : Maybe Int -> Maybe Placement -> Model a -> Maybe Int toMenuMaxHeight maxHeight forcedPlacement (Model model) = - Maybe.map2 (calculateMenuDimensionsAndPlacement maxHeight forcedPlacement) model.containerElement model.menuElement + Maybe.map2 (calculateMenuDimensionsAndPlacement maxHeight forcedPlacement) model.containerElement model.menuViewPort |> Maybe.map .maxHeight @@ -275,11 +275,11 @@ clear (Model model) = } -setElements : { container : Maybe Dom.Element, menu : Maybe Dom.Element } -> Model a -> Model a +setElements : { container : Maybe Dom.Element, menu : Maybe Dom.Viewport } -> Model a -> Model a setElements { container, menu } (Model model) = Model { model - | menuElement = menu + | menuViewPort = menu , containerElement = container } @@ -298,7 +298,7 @@ setFocused v (Model model) = -- INTERNAL -calculateMenuDimensionsAndPlacement : Maybe Int -> Maybe Placement -> Dom.Element -> Dom.Element -> { minWidth : Int, maxHeight : Int, placement : Placement } +calculateMenuDimensionsAndPlacement : Maybe Int -> Maybe Placement -> Dom.Element -> Dom.Viewport -> { minWidth : Int, maxHeight : Int, placement : Placement } calculateMenuDimensionsAndPlacement maxHeight forcedPlacement container menu = calculateMenuDimensionsAndPlacementHelper forcedPlacement diff --git a/src/Internal/Msg.elm b/src/Internal/Msg.elm index 1cb5a88..d38b458 100644 --- a/src/Internal/Msg.elm +++ b/src/Internal/Msg.elm @@ -1,6 +1,6 @@ module Internal.Msg exposing (Msg(..)) -import Browser.Dom as Dom exposing (Element) +import Browser.Dom as Dom import Internal.Option exposing (Option) @@ -12,7 +12,7 @@ type Msg a | InputLostFocus | MouseEnteredOption Int | KeyDown (List (Option a)) String - | GotContainerAndMenuElements (Result Dom.Error { menu : Element, container : Element }) + | GotContainerAndMenuElements (Result Dom.Error { menu : Dom.Viewport, container : Dom.Element }) | ClearButtonPressed | InputDebounceReturned String | GotRequestResponse String (Result () (List a)) diff --git a/src/Internal/Update.elm b/src/Internal/Update.elm index a45bb34..66225b2 100644 --- a/src/Internal/Update.elm +++ b/src/Internal/Update.elm @@ -72,7 +72,7 @@ update maybeRequest msg model = ( model |> Model.setElements { container = Maybe.map .container (Result.toMaybe result) - , menu = Maybe.map .container (Result.toMaybe result) + , menu = Maybe.map .menu (Result.toMaybe result) } |> Model.openMenu , Effect.none