DOC-2898: Documentation enhancements: for https://www.tiny.cloud/docs/tinymce/latest/custom-toggle-toolbar-button/#4071
DOC-2898: Documentation enhancements: for https://www.tiny.cloud/docs/tinymce/latest/custom-toggle-toolbar-button/#4071
Conversation
…criptions for component creation and destruction callbacks.
kemister85
left a comment
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
Missing the word "button" after Bold, and there's trailing whitespace at end of line.
| 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 |
There was a problem hiding this comment.
Typo: "togle" → "toggle"
| === 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 |
There was a problem hiding this comment.
Trailing whitespace after "updates".
| === 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)+. |
There was a problem hiding this comment.
Two issues here:
Note:should beNOTE:for AsciiDoc admonition rendering.- Inline code needs backtick wrapping (
`+code+`) to match the rest of the page — bare+code+only does passthrough without monospace.
| 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)+`. |
| 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: |
There was a problem hiding this comment.
Duplicated paragraph — remove the first occurrence.
| 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. |
There was a problem hiding this comment.
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.
| * `+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)+`. |
There was a problem hiding this comment.
Three issues on this line:
- Copy-paste error: The first link (for
.on) displayseditor.off— should beeditor.on. - Broken xref syntax: There's an extra leading backtick before each
xref:. The codebase pattern isxref:page.adoc#anchor[\+code+`]without a wrapping backtick (seecustomize-ui.adoc,upload-images.adoc` for examples). - Since
onSetup.adocis a shared partial included across multiple pages, these broken links would affect more than just this page.
| 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)+`. |
Ticket: DOC-2898
Site: Staging branch
Changes:
Pre-checks:
feature/<version>/,hotfix/<version>/,staging/<version>/, orrelease/<version>/.modules/ROOT/nav.adochas been updated(if applicable).release noteentry for anyNew product features.productminorversioninantora.ymland added new supported versions entry inmodules/ROOT/partials/misc/supported-versions.adoc.Review: