lightning-base-components 1.18.6-alpha → 1.18.7-alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/metadata/raptor.json +5 -0
- package/package.json +10 -59
- package/scopedImports/@salesforce-label-LightningPill.delete.js +1 -1
- package/scopedImports/@salesforce-label-LightningPill.deleteAndNavigate.js +1 -1
- package/scopedImports/@salesforce-label-LightningPill.remove.js +1 -1
- package/scopedImports/@salesforce-label-LightningRecordPicker.dataSourceErrorMessage.js +1 -0
- package/scopedImports/@salesforce-label-LightningRecordPicker.invalidConfigurationErrorMessage.js +1 -0
- package/src/lightning/accordion/accordion.css +2 -2
- package/src/lightning/accordion/accordion.js +2 -4
- package/src/lightning/accordionSection/accordionSection.css +2 -2
- package/src/lightning/accordionSection/accordionSection.js +2 -4
- package/src/lightning/avatar/avatar.css +2 -2
- package/src/lightning/avatar/avatar.js +2 -3
- package/src/lightning/baseCombobox/baseCombobox.css +2 -2
- package/src/lightning/baseCombobox/baseCombobox.js +37 -85
- package/src/lightning/baseComboboxItem/baseComboboxItem.js +2 -4
- package/src/lightning/baseComboboxItem/inline.css +2 -2
- package/src/lightning/breadcrumb/breadcrumb.css +2 -2
- package/src/lightning/breadcrumb/breadcrumb.js +2 -4
- package/src/lightning/breadcrumbs/breadcrumbs.css +2 -2
- package/src/lightning/breadcrumbs/breadcrumbs.js +2 -3
- package/src/lightning/button/button.css +2 -2
- package/src/lightning/buttonGroup/buttonGroup.css +2 -2
- package/src/lightning/buttonGroup/buttonGroup.js +2 -3
- package/src/lightning/buttonIcon/buttonIcon.css +2 -2
- package/src/lightning/buttonIcon/buttonIcon.js +0 -1
- package/src/lightning/buttonIconStateful/buttonIconStateful.css +2 -2
- package/src/lightning/buttonMenu/buttonMenu.css +2 -2
- package/src/lightning/buttonMenu/buttonMenu.js +2 -4
- package/src/lightning/buttonStateful/buttonStateful.css +2 -2
- package/src/lightning/buttonStateful/buttonStateful.js +2 -3
- package/src/lightning/calendar/calendar.css +2 -2
- package/src/lightning/calendar/calendar.js +2 -4
- package/src/lightning/card/card.css +2 -2
- package/src/lightning/card/card.js +2 -3
- package/src/lightning/colorPickerCustom/colorPickerCustom.css +2 -2
- package/src/lightning/colorPickerCustom/colorPickerCustom.js +2 -3
- package/src/lightning/colorPickerPanel/colorPickerPanel.css +2 -2
- package/src/lightning/colorPickerPanel/colorPickerPanel.js +2 -4
- package/src/lightning/combobox/combobox.css +2 -2
- package/src/lightning/combobox/combobox.js +2 -4
- package/src/lightning/datepicker/datepicker.css +2 -2
- package/src/lightning/datepicker/datepicker.js +2 -4
- package/src/lightning/datetimepicker/datetimepicker.css +2 -2
- package/src/lightning/datetimepicker/datetimepicker.js +2 -4
- package/src/lightning/dualListbox/dualListbox.css +2 -2
- package/src/lightning/dualListbox/dualListbox.js +2 -4
- package/src/lightning/dynamicIcon/dynamicIcon.js +2 -3
- package/src/lightning/dynamicIcon/ellie.css +1 -1
- package/src/lightning/dynamicIcon/eq.css +1 -1
- package/src/lightning/dynamicIcon/score.css +1 -1
- package/src/lightning/dynamicIcon/strength.css +1 -1
- package/src/lightning/dynamicIcon/trend.css +1 -1
- package/src/lightning/dynamicIcon/waffle.css +1 -1
- package/src/lightning/f6Controller/f6Controller.js +1 -1
- package/src/lightning/formattedRichText/formattedRichText.css +2 -2
- package/src/lightning/formattedRichText/formattedRichText.js +2 -4
- package/src/lightning/formattedText/formattedText.css +1 -1
- package/src/lightning/formattedText/formattedText.js +2 -3
- package/src/lightning/helptext/helptext.css +2 -2
- package/src/lightning/helptext/helptext.js +2 -3
- package/src/lightning/icon/icon.css +2 -2
- package/src/lightning/icon/icon.js +3 -10
- package/src/lightning/input/__examples__/checkboxbutton/checkboxbutton.html +1 -2
- package/src/lightning/input/__examples__/checkboxbutton/checkboxbutton.js +1 -1
- package/src/lightning/input/__examples__/number/number.html +5 -0
- package/src/lightning/input/input.css +4 -2
- package/src/lightning/input/input.html +239 -149
- package/src/lightning/input/input.js +532 -209
- package/src/lightning/{inputUtils/number.js → input/numberUtil.js} +1 -1
- package/src/lightning/inputUtils/inputUtils.js +20 -15
- package/src/lightning/inputUtils/normalize.js +0 -7
- package/src/lightning/layout/layout.css +2 -2
- package/src/lightning/layout/layout.js +2 -6
- package/src/lightning/layoutItem/layoutItem.css +2 -2
- package/src/lightning/layoutItem/layoutItem.js +2 -6
- package/src/lightning/menuDivider/menuDivider.css +2 -2
- package/src/lightning/menuDivider/menuDivider.js +2 -4
- package/src/lightning/menuItem/menuItem.css +2 -2
- package/src/lightning/menuItem/menuItem.js +2 -4
- package/src/lightning/menuSubheader/menuSubheader.css +2 -2
- package/src/lightning/menuSubheader/menuSubheader.js +2 -4
- package/src/lightning/pill/link.css +2 -2
- package/src/lightning/pill/link.html +8 -7
- package/src/lightning/pill/pill.js +9 -6
- package/src/lightning/pill/plain.css +2 -2
- package/src/lightning/pill/plain.html +2 -2
- package/src/lightning/pill/plainLink.css +2 -2
- package/src/lightning/pill/plainLink.html +6 -6
- package/src/lightning/pillContainer/barePillContainer.css +2 -2
- package/src/lightning/pillContainer/pillContainer.js +2 -4
- package/src/lightning/pillContainer/standardPillContainer.css +2 -2
- package/src/lightning/popup/popup.css +2 -2
- package/src/lightning/popup/popup.js +2 -3
- package/src/lightning/primitiveBubble/primitiveBubble.css +2 -2
- package/src/lightning/primitiveBubble/primitiveBubble.js +2 -4
- package/src/lightning/primitiveButton/primitiveButton.js +2 -3
- package/src/lightning/primitiveColorpickerButton/primitiveColorpickerButton.css +2 -2
- package/src/lightning/primitiveColorpickerButton/primitiveColorpickerButton.js +2 -3
- package/src/lightning/primitiveIcon/primitiveIcon.css +2 -2
- package/src/lightning/primitiveIcon/primitiveIcon.js +2 -3
- package/src/lightning/radioGroup/radioGroup.css +3 -2
- package/src/lightning/radioGroup/radioGroup.js +2 -4
- package/src/lightning/routingService/routingService.js +2 -1
- package/src/lightning/select/select.css +2 -2
- package/src/lightning/select/select.js +2 -4
- package/src/lightning/select/select.js-meta.xml +2 -0
- package/src/lightning/spinner/spinner.css +2 -2
- package/src/lightning/spinner/spinner.js +5 -11
- package/src/lightning/tabBar/tabBar.css +2 -2
- package/src/lightning/tabBar/tabBar.js +2 -4
- package/src/lightning/timepicker/timepicker.css +2 -2
- package/src/lightning/timepicker/timepicker.js +2 -4
- package/src/lightning/toast/__docs__/toast.md +2 -2
- package/src/lightning/toast/toast.css +2 -2
- package/src/lightning/toast/toast.js +2 -4
- package/src/lightning/toastContainer/toastContainer.css +2 -2
- package/src/lightning/verticalNavigation/verticalNavigation.css +3 -2
- package/src/lightning/verticalNavigation/verticalNavigation.js +2 -3
- package/src/lightning/verticalNavigationSection/verticalNavigationSection.css +3 -2
- package/src/lightning/verticalNavigationSection/verticalNavigationSection.js +2 -3
- package/src/lightning/input/__examples__/checkboxbutton/checkboxbutton.css +0 -6
- package/src/lightning/inputUtils/utils.js +0 -18
- package/src/lightning/primitiveInputCheckbox/form-element.slds.css +0 -281
- package/src/lightning/primitiveInputCheckbox/primitiveInputCheckbox.css +0 -3
- package/src/lightning/primitiveInputCheckbox/primitiveInputCheckbox.html +0 -48
- package/src/lightning/primitiveInputCheckbox/primitiveInputCheckbox.js +0 -139
- package/src/lightning/primitiveInputCheckboxButton/form-element.slds.css +0 -281
- package/src/lightning/primitiveInputCheckboxButton/input-checkbox-button.slds.css +0 -126
- package/src/lightning/primitiveInputCheckboxButton/primitiveInputCheckboxButton.css +0 -6
- package/src/lightning/primitiveInputCheckboxButton/primitiveInputCheckboxButton.html +0 -24
- package/src/lightning/primitiveInputCheckboxButton/primitiveInputCheckboxButton.js +0 -176
- package/src/lightning/primitiveInputColor/form-element.slds.css +0 -281
- package/src/lightning/primitiveInputColor/input-color.slds.css +0 -35
- package/src/lightning/primitiveInputColor/primitiveInputColor.css +0 -4
- package/src/lightning/primitiveInputColor/primitiveInputColor.html +0 -50
- package/src/lightning/primitiveInputColor/primitiveInputColor.js +0 -184
- package/src/lightning/primitiveInputFile/button.slds.css +0 -527
- package/src/lightning/primitiveInputFile/form-element.slds.css +0 -281
- package/src/lightning/primitiveInputFile/input-file.slds.css +0 -62
- package/src/lightning/primitiveInputFile/primitiveInputFile.css +0 -5
- package/src/lightning/primitiveInputFile/primitiveInputFile.html +0 -45
- package/src/lightning/primitiveInputFile/primitiveInputFile.js +0 -111
- package/src/lightning/primitiveInputRadio/primitiveInputRadio.html +0 -24
- package/src/lightning/primitiveInputRadio/primitiveInputRadio.js +0 -103
- package/src/lightning/primitiveInputSimple/form-element.slds.css +0 -281
- package/src/lightning/primitiveInputSimple/input-text.slds.css +0 -398
- package/src/lightning/primitiveInputSimple/primitiveInputSimple.css +0 -9
- package/src/lightning/primitiveInputSimple/primitiveInputSimple.html +0 -65
- package/src/lightning/primitiveInputSimple/primitiveInputSimple.js +0 -585
- package/src/lightning/primitiveInputToggle/form-element.slds.css +0 -281
- package/src/lightning/primitiveInputToggle/input-toggle.slds.css +0 -170
- package/src/lightning/primitiveInputToggle/primitiveInputToggle.css +0 -3
- package/src/lightning/primitiveInputToggle/primitiveInputToggle.html +0 -34
- package/src/lightning/primitiveInputToggle/primitiveInputToggle.js +0 -164
- /package/src/lightning/{inputUtils/email.js → input/emailUtil.js} +0 -0
- /package/src/lightning/{primitiveInputCheckbox → input}/input-checkbox.slds.css +0 -0
- /package/src/lightning/{primitiveInputColor → input}/input-text.slds.css +0 -0
- /package/src/lightning/{primitiveInputSimple → input}/normalize.js +0 -0
- /package/src/lightning/{primitiveInputSimple → input}/selection.js +0 -0
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div part="input-text">
|
|
3
|
-
<template if:false={hasExternalLabel}>
|
|
4
|
-
<label class={computedLabelClass} for="input" part="label">
|
|
5
|
-
<template if:true={required}>
|
|
6
|
-
<abbr class="slds-required" title={i18n.required}>*</abbr>
|
|
7
|
-
</template>
|
|
8
|
-
{label}
|
|
9
|
-
</label>
|
|
10
|
-
<lightning-helptext if:true={fieldLevelHelp} content={fieldLevelHelp} alternative-text={helptextAlternativeText}></lightning-helptext>
|
|
11
|
-
</template>
|
|
12
|
-
<div class={computedFormElementClass} part="input-container" type={internalType}>
|
|
13
|
-
<input
|
|
14
|
-
accesskey={accessKey}
|
|
15
|
-
aria-errormessage="help-message"
|
|
16
|
-
aria-haspopup={ariaHasPopup}
|
|
17
|
-
aria-invalid={ariaInvalid}
|
|
18
|
-
aria-label={ariaLabel}
|
|
19
|
-
autocomplete={autocomplete}
|
|
20
|
-
class="slds-input"
|
|
21
|
-
disabled={disabled}
|
|
22
|
-
id="input"
|
|
23
|
-
inputmode={inputMode}
|
|
24
|
-
max={max}
|
|
25
|
-
maxlength={maxLength}
|
|
26
|
-
min={min}
|
|
27
|
-
minlength={minLength}
|
|
28
|
-
name={name}
|
|
29
|
-
onblur={handleBlur}
|
|
30
|
-
onchange={handleChange}
|
|
31
|
-
onfocus={handleFocus}
|
|
32
|
-
oninput={handleInput}
|
|
33
|
-
onkeydown={handleKeyDown}
|
|
34
|
-
part="input"
|
|
35
|
-
pattern={pattern}
|
|
36
|
-
placeholder={placeholder}
|
|
37
|
-
required={required}
|
|
38
|
-
readonly={readOnly}
|
|
39
|
-
step={step}
|
|
40
|
-
type={internalType}>
|
|
41
|
-
|
|
42
|
-
<template if:true={isTypeSearch}>
|
|
43
|
-
<lightning-primitive-icon icon-name="utility:search" variant="bare" svg-class="slds-input__icon slds-input__icon_left slds-icon-text-default"></lightning-primitive-icon>
|
|
44
|
-
<div class="slds-input__icon-group slds-input__icon-group_right">
|
|
45
|
-
<template if:true={isLoading}>
|
|
46
|
-
<div role="status" class="slds-spinner slds-spinner_brand slds-spinner_x-small slds-input__spinner">
|
|
47
|
-
<span class="slds-assistive-text">{i18n.loading}</span>
|
|
48
|
-
<div class="slds-spinner__dot-a"></div>
|
|
49
|
-
<div class="slds-spinner__dot-b"></div>
|
|
50
|
-
</div>
|
|
51
|
-
</template>
|
|
52
|
-
<template if:true={showClearButton}>
|
|
53
|
-
<button data-element-id="searchClear" class="slds-input__icon slds-input__icon_right slds-button slds-button_icon" onblur={handleBlur} onclick={clearAndSetFocusOnInput}>
|
|
54
|
-
<lightning-primitive-icon icon-name="utility:clear" variant="bare" svg-class="slds-button__icon"></lightning-primitive-icon>
|
|
55
|
-
<span class="slds-assistive-text">{i18n.clear}</span>
|
|
56
|
-
</button>
|
|
57
|
-
</template>
|
|
58
|
-
</div>
|
|
59
|
-
</template>
|
|
60
|
-
</div>
|
|
61
|
-
</div>
|
|
62
|
-
<template if:true={_helpMessage}>
|
|
63
|
-
<div id="help-message" class="slds-form-element__help" data-help-message role="alert" part="help-text">{_helpMessage}</div>
|
|
64
|
-
</template>
|
|
65
|
-
</template>
|
|
@@ -1,585 +0,0 @@
|
|
|
1
|
-
import { api } from 'lwc';
|
|
2
|
-
import LightningShadowBaseClass from 'lightning/shadowBaseClassPrivate';
|
|
3
|
-
import labelRequired from '@salesforce/label/LightningControl.required';
|
|
4
|
-
import labelClearInput from '@salesforce/label/LightningControl.clear';
|
|
5
|
-
import labelLoadingIndicator from '@salesforce/label/LightningControl.loading';
|
|
6
|
-
|
|
7
|
-
import {
|
|
8
|
-
calculateFractionDigitsFromStep,
|
|
9
|
-
formatNumber,
|
|
10
|
-
fromIsoDecimal,
|
|
11
|
-
hasValidNumberShortcut,
|
|
12
|
-
hasValidNumberSymbol,
|
|
13
|
-
increaseNumberByStep,
|
|
14
|
-
isValidNumber,
|
|
15
|
-
isValidNumberCharacter,
|
|
16
|
-
stringifyNumber,
|
|
17
|
-
toIsoDecimal,
|
|
18
|
-
} from 'lightning/inputUtils';
|
|
19
|
-
|
|
20
|
-
import {
|
|
21
|
-
reflectAttribute,
|
|
22
|
-
isSafari,
|
|
23
|
-
isNativeComponent,
|
|
24
|
-
isNotUndefinedOrNull,
|
|
25
|
-
normalizeKeyValue,
|
|
26
|
-
normalizeString,
|
|
27
|
-
} from 'lightning/utilsPrivate';
|
|
28
|
-
|
|
29
|
-
import { InputSelectionCache } from './selection';
|
|
30
|
-
import { normalizeInput } from './normalize';
|
|
31
|
-
|
|
32
|
-
const i18n = {
|
|
33
|
-
required: labelRequired,
|
|
34
|
-
clear: labelClearInput,
|
|
35
|
-
loading: labelLoadingIndicator,
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
const VALID_NUMBER_FORMATTERS = [
|
|
39
|
-
'decimal',
|
|
40
|
-
'percent',
|
|
41
|
-
'percent-fixed',
|
|
42
|
-
'currency',
|
|
43
|
-
];
|
|
44
|
-
const DEFAULT_FORMATTER = VALID_NUMBER_FORMATTERS[0];
|
|
45
|
-
|
|
46
|
-
export default class LightningPrimitiveInputSimple extends LightningShadowBaseClass {
|
|
47
|
-
@api hasExternalLabel;
|
|
48
|
-
@api computedLabelClass;
|
|
49
|
-
@api required;
|
|
50
|
-
@api label;
|
|
51
|
-
@api fieldLevelHelp;
|
|
52
|
-
@api helptextAlternativeText;
|
|
53
|
-
|
|
54
|
-
@api ariaHasPopup;
|
|
55
|
-
@api accessKey;
|
|
56
|
-
@api autocomplete;
|
|
57
|
-
@api isLoading;
|
|
58
|
-
|
|
59
|
-
@api max;
|
|
60
|
-
@api min;
|
|
61
|
-
@api maxLength;
|
|
62
|
-
@api minLength;
|
|
63
|
-
@api pattern;
|
|
64
|
-
@api placeholder;
|
|
65
|
-
@api name;
|
|
66
|
-
@api readOnly;
|
|
67
|
-
@api disabled;
|
|
68
|
-
@api variant;
|
|
69
|
-
@api validity;
|
|
70
|
-
|
|
71
|
-
@api ariaLabel;
|
|
72
|
-
@api ariaInvalid;
|
|
73
|
-
|
|
74
|
-
@api
|
|
75
|
-
get ariaDescribedByElements() {
|
|
76
|
-
return this.template.querySelector('[data-help-message]');
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
@api
|
|
80
|
-
get isNativeShadow() {
|
|
81
|
-
return this._isNativeShadow;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
@api
|
|
85
|
-
get type() {
|
|
86
|
-
return this._type;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
set type(value) {
|
|
90
|
-
const normalizedValue = normalizeString(value);
|
|
91
|
-
this._type = normalizedValue;
|
|
92
|
-
|
|
93
|
-
if (this._rendered) {
|
|
94
|
-
// The type is being changed after render, which means the input element may be different (eg. changing
|
|
95
|
-
// from text to 'checkbox', so we need to set the initial value again
|
|
96
|
-
this._initialValueSet = false;
|
|
97
|
-
|
|
98
|
-
if (this.isTypeNumber) {
|
|
99
|
-
// If the type has changed, we need to re-parse the value as a number
|
|
100
|
-
this.updateNumberValue(this._value);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
@api
|
|
106
|
-
get formatter() {
|
|
107
|
-
return this._formatter;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
set formatter(value) {
|
|
111
|
-
this._formatter = normalizeString(value, {
|
|
112
|
-
fallbackValue: DEFAULT_FORMATTER,
|
|
113
|
-
validValues: VALID_NUMBER_FORMATTERS,
|
|
114
|
-
});
|
|
115
|
-
this.updateInputDisplayValueIfTypeNumber();
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
@api
|
|
119
|
-
get formatFractionDigits() {
|
|
120
|
-
return this._formatFractionDigits;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
set formatFractionDigits(value) {
|
|
124
|
-
this._formatFractionDigits = value;
|
|
125
|
-
if (this._rendered && this.isTypeNumber) {
|
|
126
|
-
this.setInputValue(this.displayedValue);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
@api
|
|
131
|
-
get step() {
|
|
132
|
-
return this._step;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
set step(value) {
|
|
136
|
-
// 'value' has already been normalized in lightning-input
|
|
137
|
-
this._step = value;
|
|
138
|
-
|
|
139
|
-
// Displayed value depends on the format number, so if we're not showing the raw
|
|
140
|
-
// number we should update the value
|
|
141
|
-
if (
|
|
142
|
-
this._rendered &&
|
|
143
|
-
this.isTypeNumber &&
|
|
144
|
-
!this._showRawNumber &&
|
|
145
|
-
this.inputElement
|
|
146
|
-
) {
|
|
147
|
-
this.setInputValue(this.displayedValue);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
@api
|
|
152
|
-
get helpMessage() {
|
|
153
|
-
return this._helpMessage;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
set helpMessage(message) {
|
|
157
|
-
this._helpMessage = message;
|
|
158
|
-
reflectAttribute(this, 'invalid', !!message);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
@api
|
|
162
|
-
get value() {
|
|
163
|
-
return this._value;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
set value(value) {
|
|
167
|
-
const previousValue = this._value;
|
|
168
|
-
|
|
169
|
-
this._value = normalizeInput(value);
|
|
170
|
-
|
|
171
|
-
if (this._rendered && this.isTypeNumber) {
|
|
172
|
-
this._value = stringifyNumber(value);
|
|
173
|
-
// the extra check for whether the value has changed is done for cases
|
|
174
|
-
// when the same value is set back in a change handler, this is to avoid
|
|
175
|
-
// the raw number from changing formatting under the user
|
|
176
|
-
// (eg. if the user typed 1,000 we want to preserve that formatting as the user
|
|
177
|
-
// types the value)
|
|
178
|
-
if (this.validity.badInput || this._value !== previousValue) {
|
|
179
|
-
this.updateNumberValue(value);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
// Again, due to the interop layer we need to check whether the value being set
|
|
184
|
-
// is different, otherwise we're duplicating the sets on the input, which result
|
|
185
|
-
// in different bugs like Japanese IME duplication of characters in Safari (likely a browser bug) or
|
|
186
|
-
// character position re-set in IE11.
|
|
187
|
-
if (this._rendered && this.inputElement.value !== this.displayedValue) {
|
|
188
|
-
this.setInputValue(this.getDisplayedValue());
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
@api
|
|
193
|
-
get inputElement() {
|
|
194
|
-
if (!this.cachedInputElement) {
|
|
195
|
-
let inputElement = this.template.querySelector('input');
|
|
196
|
-
this.cachedInputElement = inputElement;
|
|
197
|
-
}
|
|
198
|
-
return this.cachedInputElement;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
@api
|
|
202
|
-
getDisplayedValue() {
|
|
203
|
-
if (this.isTypeNumber) {
|
|
204
|
-
// When only a symbol is entered by the user, set the display value as the user's input.
|
|
205
|
-
// This will not affect the value dispatched by input via the change event, as it only dispatches a valid decimal number.
|
|
206
|
-
// Due to the above, in integrations like input-field, the user's initial input of a symbol
|
|
207
|
-
// like a minus sign will not be overwritten by an empty string value.
|
|
208
|
-
// See description in PR for more details: https://github.com/salesforce-experience-platform/lightning-components/pull/3843
|
|
209
|
-
if (
|
|
210
|
-
this.inputElement.value.length === 1 &&
|
|
211
|
-
hasValidNumberSymbol(this.inputElement.value)
|
|
212
|
-
) {
|
|
213
|
-
return this.inputElement.value;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
// If the number is not valid (bad input, step mismatch, etc.) show the raw number as
|
|
217
|
-
// well, otherwise the formatted value ends up being 'NaN' which makes it hard to
|
|
218
|
-
// see mistakes
|
|
219
|
-
if (this._showRawNumber || !this.validity.valid) {
|
|
220
|
-
if (
|
|
221
|
-
hasValidNumberShortcut(this._numberRawValue) &&
|
|
222
|
-
isValidNumber(this._numberRawValue)
|
|
223
|
-
) {
|
|
224
|
-
this._numberRawValue = fromIsoDecimal(this._value);
|
|
225
|
-
}
|
|
226
|
-
return this._numberRawValue;
|
|
227
|
-
}
|
|
228
|
-
return formatNumber(
|
|
229
|
-
this._value,
|
|
230
|
-
this.buildFormatNumberOptions(this.formatter)
|
|
231
|
-
);
|
|
232
|
-
}
|
|
233
|
-
return this._value;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
/********* PRIVATE VARIABLES *********/
|
|
237
|
-
_formatter = DEFAULT_FORMATTER;
|
|
238
|
-
_showRawNumber = false;
|
|
239
|
-
_initialValueSet = false;
|
|
240
|
-
_rendered;
|
|
241
|
-
_selectionCache;
|
|
242
|
-
_helpMessage;
|
|
243
|
-
_step;
|
|
244
|
-
_numberRawValue = '';
|
|
245
|
-
_value = '';
|
|
246
|
-
|
|
247
|
-
/********* EVENT HANDLERS *********/
|
|
248
|
-
handleFocus(event) {
|
|
249
|
-
event.stopPropagation();
|
|
250
|
-
if (this._rendered && this.isTypeNumber) {
|
|
251
|
-
this._showRawNumber = true;
|
|
252
|
-
this._selectionCache.preserve(this.inputElement);
|
|
253
|
-
this.inputElement.value = this.displayedValue;
|
|
254
|
-
this._selectionCache.restore(this.inputElement);
|
|
255
|
-
}
|
|
256
|
-
this.dispatchEvent(new CustomEvent('focus'));
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
handleBlur(event) {
|
|
260
|
-
event.stopPropagation();
|
|
261
|
-
if (this._rendered && this.isTypeNumber) {
|
|
262
|
-
this._showRawNumber = false;
|
|
263
|
-
this.setInputValue(this.displayedValue);
|
|
264
|
-
}
|
|
265
|
-
this.dispatchEvent(new CustomEvent('blur'));
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
handleKeyDown(event) {
|
|
269
|
-
if (this.isTypeNumber) {
|
|
270
|
-
// we're letting "Shift" through to prevent capital letters, other special symbols for type="number"
|
|
271
|
-
const hasMetaOrCtrlModifier = event.metaKey || event.ctrlKey;
|
|
272
|
-
// need to check that event.key is valid for "autofill" cases
|
|
273
|
-
if (!hasMetaOrCtrlModifier && !this.readOnly && event.key) {
|
|
274
|
-
const key = normalizeKeyValue(event.key);
|
|
275
|
-
|
|
276
|
-
if (key.length === 1 && !isValidNumberCharacter(key)) {
|
|
277
|
-
event.preventDefault();
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
if (key === 'ArrowUp') {
|
|
281
|
-
event.preventDefault();
|
|
282
|
-
this.numberStepUpAndDispatchEvents(1);
|
|
283
|
-
} else if (key === 'ArrowDown') {
|
|
284
|
-
event.preventDefault();
|
|
285
|
-
this.numberStepUpAndDispatchEvents(-1);
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
handleInput(event) {
|
|
292
|
-
event.stopPropagation();
|
|
293
|
-
|
|
294
|
-
if (this.isTypeNumber) {
|
|
295
|
-
// for invalid numbers the value might stay the same as the user
|
|
296
|
-
// changed the invalid input, so we need to update the raw value
|
|
297
|
-
this._numberRawValue = this.inputElement.value;
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
if (this.value === event.target.value) {
|
|
301
|
-
return;
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
this.dispatchChangeEvent();
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
handleChange(event) {
|
|
308
|
-
event.stopPropagation();
|
|
309
|
-
|
|
310
|
-
this.dispatchCommitEvent();
|
|
311
|
-
|
|
312
|
-
if (this.value === event.target.value) {
|
|
313
|
-
return;
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
this.dispatchChangeEvent();
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
/**
|
|
320
|
-
* Handle text selection.
|
|
321
|
-
* Dynamically bound to the select event by `renderedCallback`.
|
|
322
|
-
* This allows us to cache text selection in Safari, which doesn't preserve selection.
|
|
323
|
-
*/
|
|
324
|
-
handleSelect() {
|
|
325
|
-
if (isSafari) {
|
|
326
|
-
this._selectionCache.preserve(this.inputElement);
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
/********* EVENT DISPATCHERS *********/
|
|
331
|
-
|
|
332
|
-
dispatchCommitEvent() {
|
|
333
|
-
this.dispatchEvent(new CustomEvent('commit'));
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
dispatchChangeEvent() {
|
|
337
|
-
// this.interactingState.enter(); // Check for all instances of this and migrate
|
|
338
|
-
|
|
339
|
-
const detail = {};
|
|
340
|
-
|
|
341
|
-
if (this.isTypeNumber) {
|
|
342
|
-
this._numberRawValue = this.inputElement.value;
|
|
343
|
-
detail.value = toIsoDecimal(this.inputElement.value);
|
|
344
|
-
} else {
|
|
345
|
-
detail.value = this.inputElement.value;
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
// this._updateValueAndValidityAttribute(detail.value); > check this
|
|
349
|
-
this._value = detail.value;
|
|
350
|
-
// this._updateProxyInputAttributes('value');
|
|
351
|
-
|
|
352
|
-
this.dispatchChangeEventWithDetail(detail);
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
dispatchChangeEventWithDetail(detail) {
|
|
356
|
-
this.dispatchEvent(
|
|
357
|
-
new CustomEvent('change', {
|
|
358
|
-
composed: true,
|
|
359
|
-
bubbles: true,
|
|
360
|
-
detail,
|
|
361
|
-
})
|
|
362
|
-
);
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
/********* TYPE GETTERS *********/
|
|
366
|
-
/**
|
|
367
|
-
* Gets the value for the actual 'type' attribute on the input element.
|
|
368
|
-
*/
|
|
369
|
-
get internalType() {
|
|
370
|
-
// Maps number->text to support shorthand input strings like '1k'.
|
|
371
|
-
if (this.isTypeNumber || this.isTypeEmail) {
|
|
372
|
-
return 'text';
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
return this.type;
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
get isTypeNumber() {
|
|
379
|
-
return this.type === 'number';
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
get isTypeEmail() {
|
|
383
|
-
// To test against native change this to type="emails"
|
|
384
|
-
return this.type === 'email';
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
get isTypeSearch() {
|
|
388
|
-
return this.type === 'search';
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
get isTypeText() {
|
|
392
|
-
return this.type === 'text';
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
/***** GETTERS *****/
|
|
396
|
-
|
|
397
|
-
get showClearButton() {
|
|
398
|
-
return (
|
|
399
|
-
this.isTypeSearch &&
|
|
400
|
-
isNotUndefinedOrNull(this._value) &&
|
|
401
|
-
this._value !== ''
|
|
402
|
-
);
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
get inputMode() {
|
|
406
|
-
if (this.isTypeNumber) {
|
|
407
|
-
return 'decimal';
|
|
408
|
-
} else if (this.isTypeEmail) {
|
|
409
|
-
return 'email';
|
|
410
|
-
}
|
|
411
|
-
return null;
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
get displayedValue() {
|
|
415
|
-
return this.getDisplayedValue();
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
get i18n() {
|
|
419
|
-
return i18n;
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
get computedFormElementClass() {
|
|
423
|
-
return this.isTypeSearch
|
|
424
|
-
? 'slds-form-element__control slds-grow slds-input-has-icon slds-input-has-icon_left-right'
|
|
425
|
-
: 'slds-form-element__control slds-grow';
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
/********* NUMBER *********/
|
|
429
|
-
|
|
430
|
-
updateNumberValue(value) {
|
|
431
|
-
const newValue = stringifyNumber(value);
|
|
432
|
-
this._value = newValue;
|
|
433
|
-
this._numberRawValue = fromIsoDecimal(newValue);
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
/**
|
|
437
|
-
* Increases (if increment is positive, decreases otherwise) the number value of the input by the increment
|
|
438
|
-
* multiple of the given 'step'. Additionally dispatches the 'change' and 'commit' events.
|
|
439
|
-
*
|
|
440
|
-
* @param {Number} increment A multiple of the step to increase, when step is 'any',
|
|
441
|
-
* the step is assumed to be 1.
|
|
442
|
-
* @private
|
|
443
|
-
*/
|
|
444
|
-
numberStepUpAndDispatchEvents(increment) {
|
|
445
|
-
if (this._readOnly || this._disabled) {
|
|
446
|
-
return;
|
|
447
|
-
}
|
|
448
|
-
this._value = increaseNumberByStep({
|
|
449
|
-
value: this._value,
|
|
450
|
-
step: this.step,
|
|
451
|
-
increment,
|
|
452
|
-
fractionDigits: this.buildFormatNumberOptions(this.formatter)
|
|
453
|
-
.minimumFractionDigits,
|
|
454
|
-
});
|
|
455
|
-
|
|
456
|
-
// Raw value is the value the user entered (we preserve a user's input),
|
|
457
|
-
// since we're generating a new value we're overriding it
|
|
458
|
-
this._numberRawValue = fromIsoDecimal(this._value);
|
|
459
|
-
|
|
460
|
-
this.setInputValue(this.displayedValue);
|
|
461
|
-
|
|
462
|
-
this.dispatchChangeEvent();
|
|
463
|
-
this.dispatchCommitEvent();
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
buildFormatNumberOptions(formatter) {
|
|
467
|
-
const options = {
|
|
468
|
-
style: formatter,
|
|
469
|
-
};
|
|
470
|
-
// Use the min/max fraction digits from the formatFractionDigits provided by the user if available.
|
|
471
|
-
// Otherwise, use the number of digits calculated from step
|
|
472
|
-
if (this._formatFractionDigits !== undefined) {
|
|
473
|
-
options.minimumFractionDigits = this._formatFractionDigits;
|
|
474
|
-
options.maximumFractionDigits = this._formatFractionDigits;
|
|
475
|
-
} else {
|
|
476
|
-
let digitsFromStep = calculateFractionDigitsFromStep(this._step);
|
|
477
|
-
// if formatting percentages, when calculating digits from step, take into
|
|
478
|
-
// consideration that the formatted number is effectively multiplied by 10^2, ie. 0.1 is 10%
|
|
479
|
-
// so we need to subtract 2 digits;
|
|
480
|
-
if (formatter === 'percent' && typeof digitsFromStep === 'number') {
|
|
481
|
-
digitsFromStep -= 2;
|
|
482
|
-
if (digitsFromStep < 0) {
|
|
483
|
-
digitsFromStep = 0;
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
options.minimumFractionDigits = digitsFromStep;
|
|
488
|
-
options.maximumFractionDigits = digitsFromStep;
|
|
489
|
-
}
|
|
490
|
-
return options;
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
updateInputDisplayValueIfTypeNumber() {
|
|
494
|
-
// Displayed value depends on the format number, so if we're not showing the raw
|
|
495
|
-
// number we should update the value
|
|
496
|
-
if (
|
|
497
|
-
this._rendered &&
|
|
498
|
-
this.isTypeNumber &&
|
|
499
|
-
!this._showRawNumber &&
|
|
500
|
-
this.inputElement
|
|
501
|
-
) {
|
|
502
|
-
this.setInputValue(this.displayedValue);
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
/** ---- */
|
|
507
|
-
|
|
508
|
-
clearAndSetFocusOnInput(event) {
|
|
509
|
-
// TODO: Discuss this, it seems the wrong thing to do.
|
|
510
|
-
// button is removed from template, but
|
|
511
|
-
// event still is propagated, For example, captured by panel,
|
|
512
|
-
// then cause panel think is clicked outside.
|
|
513
|
-
event.stopPropagation();
|
|
514
|
-
|
|
515
|
-
this.setInputValue('');
|
|
516
|
-
this._value = '';
|
|
517
|
-
// this._updateValueAndValidityAttribute('');
|
|
518
|
-
|
|
519
|
-
this.inputElement.focus();
|
|
520
|
-
|
|
521
|
-
this.dispatchChangeEventWithDetail({
|
|
522
|
-
value: this._value,
|
|
523
|
-
});
|
|
524
|
-
|
|
525
|
-
this.dispatchCommitEvent();
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
setInputValue(value) {
|
|
529
|
-
if (this._inputDragonDecorated) {
|
|
530
|
-
// The underlying input has been modified to dispatch an 'input' event when a direct value set
|
|
531
|
-
// is used to allow for Dragon Natural Speaking (which sets the value directly on the inputs instead
|
|
532
|
-
// dispatching an input event against the input). Since we're in a programatic set here (ie. set
|
|
533
|
-
// not resulting from a direct user interaction) we want a default setter behaviour that doesn't
|
|
534
|
-
// dispatch any events.
|
|
535
|
-
// setDecoratedDragonInputValueWithoutEvent(this.inputElement, value);
|
|
536
|
-
} else {
|
|
537
|
-
this.inputElement.value = value;
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
connectedCallback() {
|
|
542
|
-
super.connectedCallback();
|
|
543
|
-
if (this.isTypeNumber) {
|
|
544
|
-
this.updateNumberValue(this._value);
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
// Using this mechanism to communicate to AriaObserver in lightning-input
|
|
548
|
-
// that the primitive is in native shadow and it needs to copy content over
|
|
549
|
-
this._isNativeShadow = isNativeComponent(this);
|
|
550
|
-
}
|
|
551
|
-
|
|
552
|
-
renderedCallback() {
|
|
553
|
-
// For W-7962838: In Safari, focus doesn't scroll input into view.
|
|
554
|
-
// Attach the event listener used to cache the selected text when selection changes.
|
|
555
|
-
if (isSafari) {
|
|
556
|
-
this.inputElement.addEventListener(
|
|
557
|
-
'select',
|
|
558
|
-
this.handleSelect.bind(this)
|
|
559
|
-
);
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
if (!this._initialValueSet && this.inputElement) {
|
|
563
|
-
this._rendered = true;
|
|
564
|
-
|
|
565
|
-
if (this.isTypeNumber) {
|
|
566
|
-
this._numberRawValue = fromIsoDecimal(this._value);
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
this.setInputValue(this.displayedValue);
|
|
570
|
-
this._initialValueSet = true;
|
|
571
|
-
}
|
|
572
|
-
|
|
573
|
-
reflectAttribute(this, 'variant', this.variant);
|
|
574
|
-
reflectAttribute(this, 'disabled', this.disabled);
|
|
575
|
-
reflectAttribute(this, 'readonly', this.readOnly);
|
|
576
|
-
}
|
|
577
|
-
constructor() {
|
|
578
|
-
super();
|
|
579
|
-
|
|
580
|
-
// The selection cache allows us an input to remember what text was selected
|
|
581
|
-
// in cases where we change the text on blur or in browsers (Safari) that
|
|
582
|
-
// don't track it properly.
|
|
583
|
-
this._selectionCache = new InputSelectionCache();
|
|
584
|
-
}
|
|
585
|
-
}
|