Fix project name overflow and add 6-word validation limit (#972)
* Fix project name overflow and add validation This commit addresses issue #971 by implementing both UI fixes and validation to prevent excessively long project names. Changes: 1. Add word-break and line-clamp to ProjectBanner.tsx to handle overflow gracefully with line-clamp-3 for names 2. Add frontend validation in ProjectModal.tsx limiting names to 6 words maximum 3. Add backend validation in project.js model with custom wordCount validator 4. Show user-friendly error messages when validation fails This ensures project names remain concise and UI-friendly while preventing the extreme overflow cases that were possible before. Fixes #971 * Add overflow-hidden to make line-clamp work properly The line-clamp utility requires explicit overflow-hidden to function correctly. Without it, the text continues to display in full rather than being truncated with ellipsis. * Fix line-clamp using inline CSS styles Tailwind's line-clamp utilities weren't working, so switched to using inline styles with the standard CSS approach: - display: -webkit-box - -webkit-line-clamp: 3 - -webkit-box-orient: vertical This ensures the text truncation works reliably across browsers. * Use Tailwind line-clamp utilities (already defined in CSS) The project already has line-clamp-1/2/3 utilities properly defined in tailwind.css with all the necessary webkit properties. Simplified the component to use these existing utilities instead of inline styles. * Add dedicated CSS classes with !important for line-clamp Created custom project-name-clamp and project-desc-clamp classes with !important flags to ensure they override any conflicting styles. This should finally fix the text truncation issue. * Use component-scoped styles for line-clamp Adding inline style tag in the component to ensure the line-clamp CSS is definitely loaded and applied. This bypasses any potential issues with external CSS compilation or loading order. * Change project name line-clamp from 3 to 2 lines Limiting project name display to 2 lines with ellipsis for better visual density and cleaner appearance. * Increase line-height for project name in banner Added line-height: 1.3 to project name for better readability and visual spacing between lines.
This commit is contained in:
parent
402d5b05e1
commit
e80847b01f
4 changed files with 67 additions and 3 deletions
|
|
@ -19,6 +19,23 @@ module.exports = (sequelize) => {
|
|||
name: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
validate: {
|
||||
notEmpty: {
|
||||
msg: 'Project name is required',
|
||||
},
|
||||
wordCount(value) {
|
||||
const MAX_WORDS = 6;
|
||||
const wordCount = value
|
||||
.trim()
|
||||
.split(/\s+/)
|
||||
.filter((word) => word.length > 0).length;
|
||||
if (wordCount > MAX_WORDS) {
|
||||
throw new Error(
|
||||
`Project name must be ${MAX_WORDS} words or less`
|
||||
);
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
description: {
|
||||
type: DataTypes.TEXT,
|
||||
|
|
|
|||
|
|
@ -45,6 +45,23 @@ const ProjectBanner: React.FC<ProjectBannerProps> = ({
|
|||
|
||||
return (
|
||||
<div className="w-full">
|
||||
<style>{`
|
||||
.project-banner-name {
|
||||
display: -webkit-box;
|
||||
-webkit-box-orient: vertical;
|
||||
-webkit-line-clamp: 2;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
line-height: 1.3;
|
||||
}
|
||||
.project-banner-desc {
|
||||
display: -webkit-box;
|
||||
-webkit-box-orient: vertical;
|
||||
-webkit-line-clamp: 2;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
`}</style>
|
||||
<div className="mb-6 overflow-hidden relative group">
|
||||
{project.image_url ? (
|
||||
<img
|
||||
|
|
@ -63,12 +80,12 @@ const ProjectBanner: React.FC<ProjectBannerProps> = ({
|
|||
)}
|
||||
|
||||
<div className="absolute inset-0 bg-black bg-opacity-40 flex items-center justify-center">
|
||||
<div className="text-center px-4">
|
||||
<h1 className="text-4xl md:text-5xl font-bold text-white drop-shadow-lg">
|
||||
<div className="text-center px-4 w-full max-w-5xl">
|
||||
<h1 className="text-4xl md:text-5xl font-bold text-white drop-shadow-lg project-banner-name">
|
||||
{project.name}
|
||||
</h1>
|
||||
{project.description && (
|
||||
<p className="text-lg md:text-xl text-white/90 mt-2 font-light drop-shadow-md max-w-2xl mx-auto">
|
||||
<p className="text-lg md:text-xl text-white/90 mt-2 font-light drop-shadow-md max-w-2xl mx-auto project-banner-desc">
|
||||
{project.description}
|
||||
</p>
|
||||
)}
|
||||
|
|
|
|||
|
|
@ -268,6 +268,21 @@ const ProjectModal: React.FC<ProjectModalProps> = ({
|
|||
return;
|
||||
}
|
||||
|
||||
const MAX_WORDS = 6;
|
||||
const wordCount = formData.name
|
||||
.trim()
|
||||
.split(/\s+/)
|
||||
.filter((word) => word.length > 0).length;
|
||||
if (wordCount > MAX_WORDS) {
|
||||
setError(
|
||||
t(
|
||||
'errors.projectNameTooLong',
|
||||
`Project name must be ${MAX_WORDS} words or less`
|
||||
)
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
setIsSaving(true);
|
||||
try {
|
||||
// Add new tags to the global store
|
||||
|
|
|
|||
|
|
@ -170,6 +170,21 @@ select:focus {
|
|||
display: none; /* Chrome/Safari */
|
||||
}
|
||||
|
||||
/* Project name and description line clamp */
|
||||
.project-name-clamp {
|
||||
display: -webkit-box !important;
|
||||
-webkit-box-orient: vertical !important;
|
||||
-webkit-line-clamp: 3 !important;
|
||||
overflow: hidden !important;
|
||||
}
|
||||
|
||||
.project-desc-clamp {
|
||||
display: -webkit-box !important;
|
||||
-webkit-box-orient: vertical !important;
|
||||
-webkit-line-clamp: 2 !important;
|
||||
overflow: hidden !important;
|
||||
}
|
||||
|
||||
@layer utilities {
|
||||
.line-clamp-1,
|
||||
.line-clamp-2,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue