ToggleButton
ic.ToggleButton is a latching button that holds an on/off state, similar to a hardware push-button that clicks in and clicks out. It stores its value as "on" or "off" and shows a small indicator dot that lights up when active. Use it for persistent toggles like mute, record, or enable/disable controls where a ic.Checkbox or ic.Switch would feel out of place.
Variants
Variant controls the color of the button when pressed in. primary works for most general-purpose toggles, secondary gives a subtler look when the button sits alongside other prominent controls, and destructive signals that the active state is dangerous or irreversible (think a “Record” or “Arm” button).
Size and label
Size scales the button padding and font together. Label sets the text shown next to the indicator dot. When there is no label the button renders as a compact indicator-only toggle, which is useful in tight toolbar layouts.
Disabled state
Setting Disabled to true prevents interaction and dims the button. The toggle state is preserved but the user cannot change it.
Events
ToggleButton fires a ValueChanged event each time the user clicks it, carrying the new state ("on" or "off") in the payload. In MATLAB, attach a listener with addlistener and read the value from evt.Data.value.
Custom styling
Every component exposes a .css property that lets you inject instance-level CSS directly from MATLAB. Here is a rounded red “REC” button as an example. The selectors target .ic-toggle-btn for the base shape and its --on modifier for the active glow.
tb = ic.ToggleButton("Label", "REC", "Size", "lg");
tb.Value = "on";
tb.css.style(".ic-toggle-btn", ...
"border_radius", "20px", ...
"padding", "0.5rem 1.25rem");
tb.css.style(".ic-toggle-btn.ic-toggle-btn--on", ...
"background_color", "#dc2626", ...
"box_shadow", "0 0 12px rgba(220, 38, 38, 0.5)");
tb.css.style(".ic-toggle-btn__indicator", ...
"width", "8px", ...
"height", "8px");linear-gradient, backdrop-filter, or newer color functions may not work everywhere. For reference, MATLAB R2024b uses Chromium 104.
Always test your custom styles in the MATLAB version you are targeting, and use canIuse to check compatibility of specific CSS features if you know the browser version MATLAB is using.
Use the Developer Tools component to inspect the DOM structure of each component and find the right selectors for styling.