Skip to content

Fix tess-expandable behaviour when multiple under the same parent e…#1234

Open
fbacall wants to merge 3 commits intomasterfrom
fix-see-more
Open

Fix tess-expandable behaviour when multiple under the same parent e…#1234
fbacall wants to merge 3 commits intomasterfrom
fix-see-more

Conversation

@fbacall
Copy link
Member

@fbacall fbacall commented Feb 12, 2026

Summary of changes

  • Explicitly bind the expandable "Show more" button to the expandable div, rather than relying on selector.

Motivation and context

#1231

Checklist

  • I have read and followed the CONTRIBUTING guide.
  • I confirm that I have the authority necessary to make this contribution on behalf of its copyright owner and agree
    to license it to the TeSS codebase under the
    BSD license.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes incorrect “Show more/less” toggling when multiple .tess-expandable sections exist under the same parent (Issue #1231), by explicitly associating each button with its intended expandable element instead of relying on a parent selector.

Changes:

  • Create the “Show more” button and bind it to a specific .tess-expandable element.
  • Update the click handler to use the bound target rather than parentElement.querySelector(...).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

var div = this.parentElement.querySelector('.tess-expandable');
var maxHeight = parseInt(div.dataset.origHeight) + 80;
var limit = parseInt(div.dataset.heightLimit || "300");
const div = this.expandableTarget;
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Binding the expandable div via a custom JS property (btn[0].expandableTarget) is not preserved across Turbolinks snapshot caching (custom/expando properties are lost when the DOM is serialized/cloned). Because the code also short-circuits when data-orig-height is present ("Prevent double bind"), a cached page restored via back/forward navigation can leave .tess-expandable-btn in the DOM without expandableTarget, causing the click handler to throw when it reads div.dataset.... Prefer persisting the association in the DOM (e.g., assign an id to the .tess-expandable and store it on the button via aria-controls/data-target, or re-bind expandableTarget to any existing adjacent button even when data-orig-height is already set).

Suggested change
const div = this.expandableTarget;
// Prefer the explicitly bound target, but fall back to the preceding
// .tess-expandable element. This avoids relying solely on expando
// properties, which are lost across Turbolinks snapshot caching.
var div = this.expandableTarget || $(this).prev('.tess-expandable')[0];
if (!div) {
// No associated expandable div found; do nothing to avoid errors.
return false;
}

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (1)

app/assets/javascripts/application.js:288

  • There are now two separate dataset.origHeight guards (one before computing limit, and another inside the clientHeight > limit block). The inner check looks redundant and uses return true (continue) while the outer uses return (also continue), which makes the control flow harder to follow—consider keeping just one guard for clarity.
    $('.tess-expandable').each(function () {
        if (this.dataset.origHeight) {
            return;
        }
        var limit = this.dataset.heightLimit || 300;

        if (this.clientHeight > limit) {
            if (this.dataset.origHeight) { // Prevent double bind
                return true;
            }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant