[twig] default offset not being applied when offset modifier missing

Created on 2 April 2025, 24 days ago

Problem/Motivation

I just want to say kudos to the developers for designing this module to apply a 10px offset default when no modifiers are passed. popperjs default offset is 0, way too close! I expect most of time it's overridden, at least it is in examples.

I've been playing around with popperJS on its own and noticed the default popperjs offset is 0, far too close. Plenty of ways to adjust that, and did that in a sandbox just fine. After I installed this module, I noticed the offset was also set to 0. As recommended in the documentation, using modifiers for popperjs I bumped it to 10px.

{% set options = {"content": item.tooltip_content, "placement": "auto", "modifiers": [{"name": "offset", "options": {"offset": [0, 10]}}]} %}

I figure maybe I should just set that default in tooltip.js, so I don't need to maintain a bunch of nested objects, arrays in twig. When in tooltip.js, instanciateTooltip() is already built to set a default of 10. That's what I was going to set it to anyways, but then why wasn't it applying when I wasn't using a modifier?

Steps to reproduce

Use the twig examples in the documentation, don't use 'modifiers' and the tooltip is right up against the triggering element. console.log() the incoming attr.modifiers, etc.

Proposed resolution

When we check whether an offset modifier is passed, use 'some' instead of 'filter' so it properly detects the fallback empty array when attr.modifiers is undefined so it can push the offset.

πŸ› Bug report
Status

Active

Version

1.1

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States spelcheck

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024