Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

fix: variant tag causing undefined behavior

thecodrrc9dccbc84a33
diff --git a/apps/web/src/common/dialogcontroller.js b/apps/web/src/common/dialogcontroller.js
index 2ca5a9e7b..207b7cf7d 100644
--- a/apps/web/src/common/dialogcontroller.js
+++ b/apps/web/src/common/dialogcontroller.js
@@ -458,11 +458,15 @@ export function showCreateTagDialog() {
perform(false);
}}
onAction={async (title) => {
- if (!title) return;
- await db.tags.add(title);
- showToast("success", "Tag created!");
- tagStore.refresh();
- perform(true);
+ if (!title) return showToast("error", "Tag title cannot be empty.");
+ try {
+ await db.tags.add(title);
+ showToast("success", "Tag created!");
+ tagStore.refresh();
+ perform(true);
+ } catch (e) {
+ showToast("error", e.message);
+ }
}}
/>
));
diff --git a/apps/web/src/components/editor/header.js b/apps/web/src/components/editor/header.js
index 6a7178d9f..fdbd09209 100644
--- a/apps/web/src/components/editor/header.js
+++ b/apps/web/src/components/editor/header.js
@@ -27,7 +27,7 @@ function Header() {
/>
{id && (
- <Flex alignItems="center" flexWrap="wrap">
+ <Flex alignItems="center" flexWrap="wrap" sx={{ lineHeight: 2.5 }}>
{tags.map((tag) => (
<IconTag
testId={`tag-${tag}`}
@@ -36,14 +36,14 @@ function Header() {
icon={Icon.Tag}
title={`Click to remove`}
onClick={() => setTag(tag)}
- styles={{ container: { mb: 1 }, text: { fontSize: "body" } }}
+ styles={{ text: { fontSize: "body" } }}
/>
))}
<Autosuggest
sx={{ ml: 1 }}
getData={() => db.tags.all}
getFields={(item) => [db.tags.alias(item.id)]}
- limit={5}
+ limit={10}
onAdd={(value) => setTag(value)}
onSelect={(item) => setTag(item.title)}
onRemove={() => {
@@ -52,20 +52,17 @@ function Header() {
}}
customFilter={(item) => tags.indexOf(item.title) === -1}
renderSuggestion={(item, isSelected) => (
- <Flex
- flex={1}
- pr={50}
- pl={2}
- py={1}
- bg={isSelected ? "hover" : "transparent"}
- title={`Press enter or click to add this tag`}
- sx={{ cursor: "pointer" }}
- >
- <Icon.Tag size={14} />
- <Text variant="title" fontWeight="body">
+ <>
+ <Icon.Tag size={12} sx={{ flexShrink: 0 }} />
+ <Text
+ variant="subtitle"
+ fontWeight="body"
+ ml={1}
+ sx={{ textOverflow: "ellipsis" }}
+ >
{db.tags.alias(item.id)}
</Text>
- </Flex>
+ </>
)}
/>
</Flex>
@@ -108,7 +105,7 @@ function Autosuggest({
variant="clean"
width="auto"
alignSelf="flex-start"
- sx={{ width: "auto", border: "none", p: 0 }}
+ sx={{ width: "auto", border: "none", p: 0, fontSize: "body" }}
placeholder="Add a tag..."
data-test-id="editor-tag-input"
fontSize="subtitle"
@@ -122,13 +119,7 @@ function Autosuggest({
const fields = getFields(d);
return (
fields.some((field) => {
- return (
- field
- ?.normalize("NFD")
- .replace(/[\u0300-\u036f]/g, "")
- .toLowerCase()
- .indexOf(value.toLowerCase()) !== -1
- );
+ return field.startsWith(value.toLowerCase());
}) &&
(!customFilter || customFilter(d))
);
@@ -140,10 +131,11 @@ function Autosuggest({
if (selectedIndex > -1) {
onSelect(filtered[selectedIndex]);
} else {
- onAdd(e.target.value);
+ onAdd(e.target.value.toLowerCase());
}
e.target.value = "";
setFiltered([]);
+ setSelectedIndex(-1);
} else if (e.target.value === "" && e.key === "Backspace") {
onRemove();
} else if (e.key === "Escape") {
@@ -168,32 +160,38 @@ function Autosuggest({
flexDirection="column"
sx={{
position: "absolute",
- top: 25,
+ top: 35,
border: "1px solid",
borderColor: "border",
borderRadius: "default",
boxShadow: "0px 4px 10px 0px #00000022",
zIndex: 2,
+ height: 200,
+ width: 150,
+ overflowX: "hidden",
}}
bg="background"
>
{filtered.map((item, index) => (
<Button
- variant="tool"
+ variant="menuitem"
className="suggestion-item"
key={item.id}
- onMouseEnter={() => {
- setSelectedIndex(index);
- }}
onClick={(e) => {
onSelect(item);
inputRef.current.value = "";
setFiltered([]);
}}
- p={0}
m={0}
+ lineHeight="initial"
+ display="flex"
+ justifyContent="start"
+ alignItems="center"
+ bg={selectedIndex === index ? "hover" : "transparent"}
+ title={`Press enter or click to add this tag`}
+ px={2}
>
- {renderSuggestion(item, selectedIndex === index)}
+ {renderSuggestion(item)}
</Button>
))}
</Flex>
diff --git a/apps/web/src/components/icon-tag/index.js b/apps/web/src/components/icon-tag/index.js
index f8b0a83af..a37f74c81 100644
--- a/apps/web/src/components/icon-tag/index.js
+++ b/apps/web/src/components/icon-tag/index.js
@@ -11,18 +11,21 @@ function IconTag({ text, title, icon: Icon, onClick, styles, testId }) {
onClick(e);
}
}}
- title={title}
+ title={text || title}
sx={{
borderRadius: "default",
border: "1px solid",
borderColor: "border",
+ lineHeight: "initial",
":hover": {
bg: "hover",
filter: "brightness(95%)",
},
+ maxWidth: 150,
px: 1,
mr: 1,
cursor: onClick ? "pointer" : "default",
+ overflow: "hidden",
...styles?.container,
}}
bg="bgSecondary"
@@ -30,10 +33,22 @@ function IconTag({ text, title, icon: Icon, onClick, styles, testId }) {
alignItems="center"
py="2px"
>
- <Icon size={11} color={styles?.icon?.color} sx={{ ...styles?.icon }} />
+ <Icon
+ size={11}
+ color={styles?.icon?.color}
+ sx={{ ...styles?.icon, flexShrink: 0 }}
+ />
<Text
variant="body"
- sx={{ fontSize: 11, ml: "2px", p: 0, ...styles?.text }}
+ sx={{
+ fontSize: 11,
+ ml: "2px",
+ p: 0,
+ textOverflow: "ellipsis",
+ whiteSpace: "nowrap",
+ overflow: "hidden",
+ ...styles?.text,
+ }}
>
{text}
</Text>
diff --git a/apps/web/src/components/list-item/index.js b/apps/web/src/components/list-item/index.js
index df2399ed2..1ea567812 100644
--- a/apps/web/src/components/list-item/index.js
+++ b/apps/web/src/components/list-item/index.js
@@ -170,6 +170,8 @@ function ListItem(props) {
border: "1px solid",
borderColor: "primary",
},
+ overflow: "hidden",
+ maxWidth: "100%",
}}
onKeyPress={(e) => {
if (e.key === "Enter") e.target.click();
diff --git a/apps/web/src/components/menu/index.js b/apps/web/src/components/menu/index.js
index 314511155..7f81adfb9 100644
--- a/apps/web/src/components/menu/index.js
+++ b/apps/web/src/components/menu/index.js
@@ -46,7 +46,6 @@ function Menu(props) {
/>
) : (
<Button
- variant="anchor"
title={
(disabled && disabled(data) && disableReason) || title(data)
}
@@ -70,16 +69,8 @@ function Menu(props) {
flexDirection="row"
alignItems="center"
justifyContent="center"
- py={"0.7em"}
- px={3}
- sx={{
- borderRadius: 0,
- color: color || "text",
- cursor: "pointer",
- ":hover:not(:disabled)": {
- backgroundColor: "hover",
- },
- }}
+ variant="menuitem"
+ color={color || "text"}
>
{Icon && (
<Icon
diff --git a/apps/web/src/theme/variants/button.js b/apps/web/src/theme/variants/button.js
index fb5b26b0f..18bedd35d 100644
--- a/apps/web/src/theme/variants/button.js
+++ b/apps/web/src/theme/variants/button.js
@@ -11,6 +11,7 @@ class ButtonFactory {
icon: new Icon(),
shade: new Shade(),
statusitem: new StatusItem(),
+ menuitem: new MenuItem(),
};
}
}
@@ -161,3 +162,22 @@ class StatusItem {
};
}
}
+
+class MenuItem {
+ constructor() {
+ return {
+ bg: "transparent",
+ py: "8px",
+ px: 3,
+ borderRadius: 0,
+ color: "text",
+ cursor: "pointer",
+ ":hover:not(:disabled)": {
+ backgroundColor: "hover",
+ },
+ ":active:not(:disabled)": {
+ backgroundColor: "border",
+ },
+ };
+ }
+}