new Toggle_A(parent, props)
Toggle_A element. This class focuses on the specific properties of the Toggle_A component. Since it inherits from Accessor_A, all basic properties (e.g., height, width) are available but documented in the Accessor_A part.
| Name | Type | Description |
|---|---|---|
parent | HTMLElement | HTML element that is going to be the parent of the component |
props | TComponents. |
- Source
const toggle = new TComponents.Toggle_A(document.body, {
position: 'absolute',
zIndex: 1000,
});
// Render the component.
await toggle.render();Extends
Members
multi :boolean
Set if the toggle button allows multi toggled button.
- boolean
- Source
const toggle = new TComponents.Toggle_A(document.body, {
position: 'absolute',
zIndex: 1000,
});
// Render the component.
await toggle.render();
toggle.multi = true;onChange :function
Sets the onChange event handler for the toggle component. The handler can either be a string representing a function to be executed or a function itself.
- If you are using an arrow function, like
()=>{}, thethisproperty of the scope may not refer to the toggle object. - If you are using string assignment to define code execution, the string should contain
only the body of the code (executable statements), not a complete function declaration. Therefore, including function keywords like function or async function is incorrect.
- Correct (Statements Only):
xx.onChange = "console.log('Action done.');" - Incorrect (Function Declaration):
xx.onChange = "function() { console.log('Action done.'); }"
- function
- Source
const toggle = new TComponents.Toggle_A(document.body, {
position: 'absolute',
zIndex: 1000,
});
// Render the component.
await toggle.render();
// Example 1: Using a string as the handler:
toggle.onChange = "console.log(this.multi);"// Example 2: Using a function as the handler:
toggle.onChange = function () {
console.log(this.multi);
};// Example 3: Using an arrow function as the handler:
// Note that the `this` context will not refer to the toggle object
toggle.onChange = () => {
console.log(toggle.multi);
};optionItems :string
Sets the option items from a formatted string.
- string
- Source
const toggle = new TComponents.Toggle_A(document.body, {
position: 'absolute',
zIndex: 1000,
});
// Render the component.
await toggle.render();
toggle.optionItems = `text4|value4;text5|value5;text6|value6`;Methods
(protected) afterRenderOnce() → {void}
there are something need to do after render once
- Source
- Type:
- void
(protected) defaultProps() → {TComponents.ToggleProps}
Returns the default values of class properties (excluding parent properties).
- Overrides
- Source
- Type:
- TComponents.
ToggleProps
generateModel() → {Array.<any>}
Generate toggle button model with value parameter
- Source
The generated model array.
- Type:
- Array.<any>
markup() → {string}
Returns the markup for the toggle component.
- Overrides
- Source
HTML markup string.
- Type:
- string
(async) onInit() → {Promise.<void>}
Initializes the toggle component.
- Overrides
- Source
- Type:
- Promise.<void>
(async) onRender() → {Promise.<void>}
Renders the toggle component.
- Overrides
- Source
If an error occurs during rendering.
- Type
- Error
- Type:
- Promise.<void>
setToggled(index, toggled, fireCallback) → {void}
Set the toggle status of the specifc index button.
| Name | Type | Description |
|---|---|---|
index | number | the index of target button |
toggled | boolean | null: invert the status of target button; true/false: set target button to true/false |
fireCallback | boolean | True if expecting to trigger onClick event |
- Source
- Type:
- void
(static) loadCssClassFromString(css) → {void}
Add css properties to the component
| Name | Type | Description |
|---|---|---|
css | string | The css string to be loaded into style tag |
- Source
- Type:
- void
TComponents.Toggle_A.loadCssClassFromString(`
.tc-toggle {
height: inherit;
}`
);