Popover API: Input fields on mobile/ touch

  • building_stuff-1345025590566322218

    Janis

    15 days ago

    I have a popover in my app using the popover api. This popover has an input field where users can enter links. It works fine on desktop, but it doesnt work on mobile. I believe it has to do with the focus state but i cant figure out how to do it on mobile/ touch. Does anyone have an idea how to solve it?
  • Popover API: Input fields on mobile/ touch
  • jamessomers-1345037255210958953

    James

    15 days ago

    I had the same issue and I believe when you focus on mobile the browser does that scroll/zoom into view and that's what's causing it. I stopped using the popover API for now and just using css to display the dialog. But I have tested an input in the Spark dialog and that worked as expected
    πŸ‘1
  • building_stuff-1345037401197641740

    Janis

    15 days ago

    Yes I just found the answer with Claude
  • *Mobile browsers sometimes fail to update the inert state when showing the popover again. The best way to fix this is to manually remove inert and, if needed, force focus on an input field. Try Solution 1 first, and if the issue persists, use Solution 2 (manual popover handling).

    *
  • I now created a custom action to open the popover manually and it works fine πŸ™‚
  • /**
    * @param {Args} args
    * @param {Ctx} ctx
    */
    function popoverOpenAction() {
    const popover = ctx.root.getElementById(args.id);

    if (!popover) {
    console.error("Popover element not found.");
    return;
    }

    popover.showPopover();
    popover.removeAttribute("inert"); // Ensure mobile interaction works

    // Delay focus slightly to fix mobile issues
    setTimeout(() => {
    const input = popover.querySelector("input");
    if (input) {
    input.focus();
    input.scrollIntoView({ behavior: "smooth", block: "center" });
    }
    }, 100); // Adjusted delay for better mobile behavior
    }
    πŸ™Œ1
  • building_stuff-1345038398523576342

    Janis

    15 days ago

    Thank you though! πŸ™‚

Stop scrolling. Start building.

toddle is a visual web app builder that rivals custom code β€” but accessible to your entire team!

Try toddle β€” it's free!

Β© Copyright 2024 toddle. All rights reserved.