Skip to content

In 'HTMLElement.classList.toggle' the 'force' attribute works uncorrectly. #277

Open

Description

@orangebokov
export const toggle = <T extends HTMLElement> (className:string, force?:boolean) => (el:T) : boolean => el.classList.toggle(className, force)

toggle(className)(el)

In this example, if the 'force' attribute is not passed to the 'toggle' function, 'linkedom' will interpret it as being passed an attribute equal to 'undefined' and identify it as a 'false' value.

The correct way is for 'linkedom' to ignore the 'force' attribute if it is 'undefined'.

Everything works fine in the browser.

Аnd also in 'linkedom' everything works correctly if I do this check myself:

export const toggle = <T extends HTMLElement> (className:string, force?:boolean) => (el:T) : boolean => force === undefined ? el.classList.toggle(className) : el.classList.toggle(className, force)

Activity

  1. dyk1454683243-sudo commented on Sep 20, 2026

    @dyk1454683243-sudo

    Taking this: I'll treat DOMTokenList.toggle(token, force) so that force === undefined matches an omitted second argument (plain toggle), per browsers / Web IDL optional boolean. force true/false will still force-add / force-remove.

    I didn't find an open PR with Exact Fixes #277 / Closes #277. Will open a focused PR against main.

  2. dyk1454683243-sudo commented on Sep 20, 2026

    @dyk1454683243-sudo

    Opened #334 against main — toggle(token, undefined) now matches omitted force (plain toggle).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions