Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | 155x 155x 155x 155x 155x 155x 155x 155x 155x 155x 155x 155x 155x 200x 1x 1x 1x 2x 1x 201x 3x 1x 210x 210x 16x 1x 16x 16x 16x 16x 1x 16x 13x 2x 3x 1x 8x | import { LightningElement, api } from 'lwc';
import { normalizeBoolean, normalizeInput, reflectAttribute, normalizeString } from 'sds/utils';
import 'sds/privateThemeProvider';
export default class Button extends LightningElement {
static shadowSupportMode = 'native';
/**
* Internal component fields
*/
_disabled = false;
_form;
_tabIndex;
_type;
_variant;
_buttonElement;
_formElement;
/**
* defines a string value that labels an interactive element
*
* @type {string}
*/
@api ariaLabel;
/**
* Defines a string value that describes or annotates the current element.
* Not currently supported by LWC so we implement it manually.
*
* @type {string}
*/
@api ariaDescription;
/**
* Makes the element not mutable, interactable, or focusable.
*
* @type {boolean}
* @default false
*/
@api
get disabled() {
return this._disabled;
}
set disabled(value) {
this._disabled = normalizeBoolean(value);
reflectAttribute(this, 'disabled', this._disabled);
}
/**
* The id of the form that the button belongs to.
*
* @type {string}
*/
@api
get form() {
return this._form;
}
set form(value) {
this._form = value;
}
/**
* Optional identifier for the button.
*
* @type {string}
*/
@api name;
/**
* Provides semantic meaning to content, allowing screen readers and other
* tools to present and support interaction with object in a way that is
* consistent with user expectations of that type of object.
*
* @type {string}
*/
@api role;
/**
* Allows HTML elements to be focusable or prevent them from being
* sequentially focusable
*
* @type {number}
*/
@api
get tabIndex() {
return this._tabIndex;
}
set tabIndex(value) {
this._tabIndex = normalizeInput(value);
}
/**
* Text representing advisory information related to the element it belongs to.
*
* @type {string}
*/
@api title;
/**
* Specifies the type of button.
*
* @type {string}
*/
@api
get type() {
return this._type;
}
set type(value) {
this._type = normalizeString(value, {
fallbackValue: 'button',
validValues: ['button', 'reset', 'submit'],
});
}
/**
* Optional value for the button to be submitted with a form.
*
* @type {string}
*/
@api value;
/**
* Optional interface to define a button variant.
*
* @type {string}
*/
@api
get variant() {
return this._variant;
}
set variant(value) {
this._variant = value;
reflectAttribute(this, 'variant', this._variant);
}
/**
* Retrieve the form element that this button belongs to.
*
* @return {HTMLElement} - The form element.
*/
getForm() {
if (this._form) {
this._formElement = this._formElement || this.template.host.closest(`#${this._form}`);
}
return this._formElement;
}
/**
* Retrieve the button element.
* @return {HTMLElement} - The button element.
*/
get button() {
this._buttonElement = this._buttonElement || this.template.querySelector('button');
return this._buttonElement;
}
/**
* Handle the standard click event
*
* Workaround for lack of elementInternals support in LWC. Tradeoff is finding
* the form will fail if the form element lives in a shadow root outside of the
* shadow boundary that contains this component's host element.
*/
handleClick() {
const form = this.getForm();
if (form) {
form.requestSubmit();
}
if (this.button.hasAttribute('aria-pressed')) {
if (this.ariaPressed === 'false') {
this.ariaPressed = 'true';
} else {
this.ariaPressed = 'false';
}
}
}
/**
* Handle the standard focus event
*/
handleFocus() {
this.setAttribute('focus', '');
}
/**
* Handle the standard blur event
*/
handleBlur() {
this.removeAttribute('focus');
}
}
|