MCPcopy Create free account
hub / github.com/adobe/react-spectrum / commit

Function commit

packages/react-stately/src/color/useColorFieldState.ts:135–161  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

133 }, [inputValue]);
134
135 let commit = () => {
136 // Set to empty state if input value is empty
137 if (!inputValue.length) {
138 safelySetColorValue(null);
139 if (value === undefined || colorValue === null) {
140 setInputValue('');
141 } else {
142 setInputValue(colorValue.toString('hex'));
143 }
144 return;
145 }
146
147 // if it failed to parse, then reset input to formatted version of current number
148 if (parsedValue == null) {
149 setInputValue(colorValue ? colorValue.toString('hex') : '');
150 return;
151 }
152
153 safelySetColorValue(parsedValue);
154 // in a controlled state, the numberValue won't change, so we won't go back to our old input without help
155 let newColorValue = '';
156 if (colorValue) {
157 newColorValue = colorValue.toString('hex');
158 }
159 setInputValue(newColorValue);
160 validation.commitValidation();
161 };
162
163 let increment = () => {
164 let newValue = addColorValue(parsedValue, step);

Callers 2

useNumberFieldFunction · 0.50
onPasteFunction · 0.50

Calls 3

safelySetColorValueFunction · 0.85
commitValidationMethod · 0.80
toStringMethod · 0.65

Tested by

no test coverage detected