Skip to content

DOC-2898: Documentation enhancements: for https://www.tiny.cloud/docs/tinymce/latest/custom-toggle-toolbar-button/#4071

Open
jeslynbo wants to merge 2 commits intotinymce/8from
hotfix/8/testingPR
Open

DOC-2898: Documentation enhancements: for https://www.tiny.cloud/docs/tinymce/latest/custom-toggle-toolbar-button/#4071
jeslynbo wants to merge 2 commits intotinymce/8from
hotfix/8/testingPR

Conversation

@jeslynbo
Copy link
Copy Markdown

@jeslynbo jeslynbo commented Apr 16, 2026

Ticket: DOC-2898

Site: Staging branch

Changes:

  • Simplified onSetup event handling and teardown logic
  • Replacing plain inline code with a cross-referenced API link
  • Edited comments for onSetup demo
  • Ensure {product name} is being used correctly

Pre-checks:

  • Branch prefixed with feature/<version>/, hotfix/<version>/, staging/<version>/, or release/<version>/.
  • modules/ROOT/nav.adoc has been updated (if applicable).
  • Included a release note entry for any New product features.
  • If this is a minor release, updated productminorversion in antora.yml and added new supported versions entry in modules/ROOT/partials/misc/supported-versions.adoc.

Review:

  • Documentation Team Lead has reviewed

@jeslynbo jeslynbo requested review from a team, kemister85 and soritaheng as code owners April 16, 2026 01:37
@jeslynbo jeslynbo marked this pull request as draft April 16, 2026 01:40
…criptions for component creation and destruction callbacks.
@jeslynbo jeslynbo marked this pull request as ready for review April 20, 2026 09:42
Copy link
Copy Markdown
Contributor

@kemister85 kemister85 left a comment

Choose a reason for hiding this comment

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

Good improvements overall — the restructured explanation, clearer option/API descriptions, and the formatChanged documentation with unbind() are all valuable. A few issues to fix before merge (suggestions provided inline so you can commit them directly).

:keywords: toolbar, toolbarbuttons, buttons, toolbarbuttonsapi, toggle, formatChanged

A toggle button triggers an action when clicked but also has a concept of state. This means it can be toggled `+on+` and `+off+`. A toggle button gives the user visual feedback for its state through CSS styling. An example of this behavior is the *Bold* button that is highlighted when the cursor is in a word with bold formatting.
A toggle button triggers an action when clicked and maintains an active state. This means it can be toggled `+on+` or `+off+`. The toggle button provides the user visual feedback of its state through CSS styling. An example of this behavior is the *Bold*, which becomes highlighted when the cursor is within text that has bold formatting.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Missing the word "button" after Bold, and there's trailing whitespace at end of line.

Suggested change
A toggle button triggers an action when clicked and maintains an active state. This means it can be toggled `+on+` or `+off+`. The toggle button provides the user visual feedback of its state through CSS styling. An example of this behavior is the *Bold*, which becomes highlighted when the cursor is within text that has bold formatting.
A toggle button triggers an action when clicked and maintains an active state. This means it can be toggled `+on+` or `+off+`. The toggle button provides the user visual feedback of its state through CSS styling. An example of this behavior is the *Bold* button, which becomes highlighted when the cursor is within text that has bold formatting.

The example above adds two custom *strikethrough* toggle buttons. Both buttons use the xref:editor-command-identifiers.adoc[`+mceToggleFormat+`] command to apply and remove strikethrough formatting. This command toggles a specified format on and off, but only works for xref:content-formatting.adoc#formats[formats] already registered with the editor. In this example, `+strikethrough+` is the registered format.

The first button applies and removes strikethrough formatting, and its state toggles on click using `+api.setActive(!api.isActive())+`. However, the expected behavior is that the button's state will reflect whether the selected content has strikethrough formatting. For example, if the cursor is moved into editor content that has strikethrough formatting the button will become *active* and if it is moved into content that does not have strikethrough formatting the button will become *inactive*. The first button in the example does not do this, since its state only toggles when the button is clicked.
=== Basic togle: manual state management
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Typo: "togle" → "toggle"

Suggested change
=== Basic togle: manual state management
=== Basic toggle: manual state management

The first (`+customStrikethrough+`) button applies and removes strikethrough formatting. Its state toggles upon click using `+api.setActive(!api.isActive())+`. However, this button does not reflect whether the selected content has strikethrough formatting which is its expected behavior. Moving the cursor into content with strikethrough formatting does not activate the button, and moving it out does not deactivate it.

NOTE: The format name given to `+mceToggleFormat+` via `+editor.execCommand(command, ui, args)+` and to `+editor.formatter.formatChanged(formatName, callback)+` is the same.
=== State-synced toggle: automatic state updates
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Trailing whitespace after "updates".

Suggested change
=== State-synced toggle: automatic state updates
=== State-synced toggle: automatic state updates

The second button (`+customToggleStrikethrough+`) addresses this by using xref:apis/tinymce.formatter.adoc#formatChanged[`+editor.formatter.formatChanged+`] in its `+onSetup+` callback to monitor the formatting state of the current selection.

For formats that require variables, the `+editor.formatter.formatChanged+` function takes two extra arguments: `+similar+` and `+vars+`.
Note: The format name passed to +mceToggleFormat+ via +editor.execCommand(command, ui, args)+ is the same as the one used in +editor.formatter.formatChanged(formatName, callback)+.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Two issues here:

  1. Note: should be NOTE: for AsciiDoc admonition rendering.
  2. Inline code needs backtick wrapping (`+code+`) to match the rest of the page — bare +code+ only does passthrough without monospace.
Suggested change
Note: The format name passed to +mceToggleFormat+ via +editor.execCommand(command, ui, args)+ is the same as the one used in +editor.formatter.formatChanged(formatName, callback)+.
NOTE: The format name passed to `+mceToggleFormat+` via `+editor.execCommand(command, ui, args)+` is the same as the one used in `+editor.formatter.formatChanged(formatName, callback)+`.

Comment on lines +57 to +59
The `+formatChanged+` method accepts the following parameters:

The `+vars+` argument controls which variables are used to match the content when determining whether to run the callback. This argument is only used when `+similar+` is `+false+`.
The `+formatChanged+` method accepts the following parameters:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Duplicated paragraph — remove the first occurrence.

Suggested change
The `+formatChanged+` method accepts the following parameters:
The `+vars+` argument controls which variables are used to match the content when determining whether to run the callback. This argument is only used when `+similar+` is `+false+`.
The `+formatChanged+` method accepts the following parameters:
The `+formatChanged+` method accepts the following parameters:

The `+vars+` argument controls which variables are used to match the content when determining whether to run the callback. This argument is only used when `+similar+` is `+false+`.
The `+formatChanged+` method accepts the following parameters:

* `+formats+` (String, required) -- The name of the registered format to monitor.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The formatChanged first parameter accepts a comma-separated list of format names (verified against source: Formatter.ts and the existing API docs at tinymce.formatter.adoc). The current wording implies only a single name.

Suggested change
* `+formats+` (String, required) -- The name of the registered format to monitor.
* `+formats+` (String, required) -- A comma-separated list of registered format names to monitor.

----

To bind a callback function to an editor event use `+editor.on(eventName, callback)+`. To unbind an event listener use `+editor.off(eventName, callback)+`. Any event listeners _should_ be unbound in the teardown callback. The only editor event which does not need to be unbound is `+init+` e.g. `+editor.on('init', callback)+`.
To bind a callback function to an editor event use `xref:apis/tinymce.editor.adoc#on[`+editor.off(eventName, callback)+`]. To unbind an event listener use `xref:apis/tinymce.editor.adoc#off[`+editor.off(eventName, callback)+`]. Any event listeners _should_ be unbound in the teardown callback. The only editor event which does not need to be unbound is `+init+` e.g. `+editor.on('init', callback)+`.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Three issues on this line:

  1. Copy-paste error: The first link (for .on) displays editor.off — should be editor.on.
  2. Broken xref syntax: There's an extra leading backtick before each xref:. The codebase pattern is xref:page.adoc#anchor[\+code+`]without a wrapping backtick (seecustomize-ui.adoc, upload-images.adoc` for examples).
  3. Since onSetup.adoc is a shared partial included across multiple pages, these broken links would affect more than just this page.
Suggested change
To bind a callback function to an editor event use `xref:apis/tinymce.editor.adoc#on[`+editor.off(eventName, callback)+`]. To unbind an event listener use `xref:apis/tinymce.editor.adoc#off[`+editor.off(eventName, callback)+`]. Any event listeners _should_ be unbound in the teardown callback. The only editor event which does not need to be unbound is `+init+` e.g. `+editor.on('init', callback)+`.
To bind a callback function to an editor event use xref:apis/tinymce.editor.adoc#on[`+editor.on(eventName, callback)+`]. To unbind an event listener use xref:apis/tinymce.editor.adoc#off[`+editor.off(eventName, callback)+`]. Any event listeners _should_ be unbound in the teardown callback. The only editor event which does not need to be unbound is `+init+` e.g. `+editor.on('init', callback)+`.

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.

2 participants