Skip to content

Commit f3c585e

Browse files
committed
use dataset on input element to pass through extra values
1 parent d95b169 commit f3c585e

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

client/browser/FinderFileSelect.tsx

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,37 @@ interface SelectedFile {
1616
labels: string[];
1717
}
1818

19-
function parseDataset(dataset: string|object) : SelectedFile {
19+
function parseDataset(dataset: string|object) : SelectedFile|null {
2020
const data = typeof dataset === 'string' ? JSON.parse(dataset) : dataset;
21-
const {id, name, file_name, file_size, sha1, mime_type, last_modified_at, summary, download_url, thumbnail_url, labels} = data;
22-
return {id, name, file_name, file_size, sha1, mime_type, last_modified_at, summary, download_url, thumbnail_url, labels};
21+
if (data) {
22+
const {
23+
id,
24+
name,
25+
file_name,
26+
file_size,
27+
sha1,
28+
mime_type,
29+
last_modified_at,
30+
summary,
31+
download_url,
32+
thumbnail_url,
33+
labels
34+
} = data;
35+
return {
36+
id,
37+
name,
38+
file_name,
39+
file_size,
40+
sha1,
41+
mime_type,
42+
last_modified_at,
43+
summary,
44+
download_url,
45+
thumbnail_url,
46+
labels
47+
};
48+
}
49+
return null;
2350
}
2451

2552

@@ -112,6 +139,8 @@ export default function FinderFileSelect(props) {
112139
const inputElement = slotRef.current.assignedElements()[0];
113140
if (inputElement instanceof HTMLInputElement) {
114141
inputElement.value = '';
142+
inputElement.dataset.selected_file = null;
143+
inputElement.checkValidity();
115144
}
116145
}
117146

@@ -122,6 +151,7 @@ export default function FinderFileSelect(props) {
122151
if (inputElement instanceof HTMLInputElement) {
123152
inputElement.value = file.id;
124153
inputElement.dataset.selected_file = JSON.stringify(parseDataset(file));
154+
inputElement.checkValidity();
125155
}
126156
}
127157
}

0 commit comments

Comments
 (0)