Skip to content

Commit a48e7a3

Browse files
authored
Fixed a bug that caused an error when pasting into the InlineMenuEditor column. (#208)
1 parent b8729cd commit a48e7a3

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

packages/cheetah-grid/package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/cheetah-grid/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cheetah-grid",
3-
"version": "0.18.0",
3+
"version": "0.18.1",
44
"description": "Cheetah Grid is a high performance grid engine that works on canvas",
55
"keywords": [
66
"spreadsheet",

packages/cheetah-grid/src/js/columns/action/InlineMenuEditor.ts

+12-5
Original file line numberDiff line numberDiff line change
@@ -247,15 +247,15 @@ export class InlineMenuEditor<T> extends Editor<T> {
247247
): SimpleColumnMenuItemOption | undefined {
248248
const pasteOpt = _textToOptionValue(value, this._options);
249249
if (pasteOpt) {
250-
return pasteOpt.value;
250+
return pasteOpt;
251251
}
252252
const columnType = grid.getColumnType(cell.col, cell.row);
253253
if (hasOptions(columnType)) {
254254
// Find with caption.
255-
const pasteValue = value.trim();
255+
const pasteValue = normalizePasteValueStr(value);
256256
const captionOpt = array.find(
257257
columnType.options,
258-
opt => `${opt.caption}`.trim() === pasteValue
258+
opt => normalizePasteValueStr(opt.caption) === pasteValue
259259
);
260260
if (captionOpt) {
261261
return _textToOptionValue(captionOpt.value, this._options);
@@ -268,17 +268,24 @@ function _textToOptionValue(
268268
value: string,
269269
options: SimpleColumnMenuItemOption[]
270270
): SimpleColumnMenuItemOption | undefined {
271-
const pasteValue = value.trim();
271+
const pasteValue = normalizePasteValueStr(value);
272272
const pasteOpt = array.find(
273273
options,
274-
opt => `${opt.value}`.trim() === pasteValue
274+
opt => normalizePasteValueStr(opt.value) === pasteValue
275275
);
276276
if (pasteOpt) {
277277
return pasteOpt;
278278
}
279279
return undefined;
280280
}
281281

282+
function normalizePasteValueStr(value: any): string {
283+
if (value == null) {
284+
return "";
285+
}
286+
return `${value}`.trim();
287+
}
288+
282289
// eslint-disable-next-line @typescript-eslint/no-explicit-any
283290
function hasOptions(columnType: ColumnTypeAPI): columnType is MenuColumn<any> {
284291
if (columnType instanceof MenuColumn) {

0 commit comments

Comments
 (0)