The vscode-checkbox
is a web component implementation of a checkbox element.
Attribute | Type | Description |
---|---|---|
autofocus |
boolean | Determines if the element should receive document focus on page load. |
checked |
boolean | When true, the checkbox is toggled on by default. |
disabled |
boolean | Prevents the user from interacting with the button––it cannot be pressed or focused. |
readonly |
boolean | When true, the control will be immutable by user interaction. |
required |
boolean | Indicates that the user must check the checkbox before the owning form can be submitted. |
value |
string | The string to use as the value of the checkbox when submitting the form |
Attribute | Type | Description |
---|---|---|
indeterminate |
boolean | Determines if the element should render the indeterminate checkbox state. |
<vscode-checkbox>Label</vscode-checkbox>
<vscode-checkbox autofocus>Label</vscode-checkbox>
<vscode-checkbox checked>Label</vscode-checkbox>
<vscode-checkbox disabled>Label</vscode-checkbox>
<vscode-checkbox readonly>Label</vscode-checkbox>
<vscode-checkbox required>Label</vscode-checkbox>
<vscode-checkbox value="baz">Label</vscode-checkbox>
Checkboxes can also render an indeterminate state. This is achieved by getting a reference to a given checkbox using JavaScript and then setting the indeterminate
property of the checkbox to true
.
const checkbox = document.getElementById('basic-checkbox');
checkbox.indeterminate = true;
<vscode-checkbox id="basic-checkbox">Label</vscode-checkbox>
Here is an example of the Visual Studio Code Checkbox and its various attributes being used in a form.
<form>
<fieldset>
<legend>Fieldset Legend</legend>
<vscode-checkbox checked required>Checked + Required</vscode-checkbox>
<vscode-checkbox checked readonly>Checked + Readonly</vscode-checkbox>
<vscode-checkbox autofocus>Autofocus</vscode-checkbox>
<vscode-checkbox disabled>Disabled</vscode-checkbox>
<vscode-checkbox value="baz">Value Set To "baz"</vscode-checkbox>
</fieldset>
<vscode-button type="submit">Submit Button</vscode-button>
</form>