Skip to content

Latest commit

 

History

History
131 lines (101 loc) · 3.95 KB

File metadata and controls

131 lines (101 loc) · 3.95 KB

Dark Mode Text Visibility Fix

Issue Description

The featured post text was not showing properly in dark mode. While the text was being processed correctly, it wasn't visible due to insufficient contrast in dark mode.

Root Cause

The text color in dark mode was set to text-gray-300, which provides insufficient contrast against dark backgrounds, making the text difficult to read or invisible.

Solution Implemented

1. Improved Text Color Contrast

Updated the text color from text-gray-300 to text-gray-200 in dark mode across all components:

Components Updated:

  • src/pages/home/Home.jsx
  • src/pages/allBlogs/AllBlogs.jsx
  • src/components/blogPostCard/BlogPostCard.jsx

2. Added Fallback Text

Implemented fallback text to ensure content is always visible:

{truncateText(blogs?.content || '', 120) || 'Click to read more...'}

3. Enhanced Text Processing

The improved truncateText function now handles edge cases better and provides fallback content when the processed text is empty.

Changes Made

Home.jsx

// Before
<p className={`mb-6 line-clamp-3 leading-relaxed ${
  mode === 'dark' ? 'text-gray-300' : 'text-gray-600'
}`}>
  {truncateText(blogs?.content || '', 120)}
</p>

// After
<p className={`mb-6 line-clamp-3 leading-relaxed ${
  mode === 'dark' ? 'text-gray-200' : 'text-gray-600'
}`}>
  {truncateText(blogs?.content || '', 120) || 'Click to read more...'}
</p>

AllBlogs.jsx

// Before
<p className={`mb-4 line-clamp-3 ${
  mode === 'dark' ? 'text-gray-300' : 'text-gray-600'
}`}>
  {truncateText(blogs?.content || '', 120)}
</p>

// After
<p className={`mb-4 line-clamp-3 ${
  mode === 'dark' ? 'text-gray-200' : 'text-gray-600'
}`}>
  {truncateText(blogs?.content || '', 120) || 'Click to read more...'}
</p>

BlogPostCard.jsx

// Before
<p className={`text-base leading-relaxed mb-4 opacity-80 ${
  mode === 'dark' ? 'text-gray-300' : 'text-gray-600'
}`}>
  {truncateText(blogs.content, 120, id)}
</p>

// After
<p className={`text-base leading-relaxed mb-4 opacity-80 ${
  mode === 'dark' ? 'text-gray-200' : 'text-gray-600'
}`}>
  {truncateText(blogs.content, 120, id) || 'Click to read more...'}
</p>

Color Comparison

Before (text-gray-300)

  • Light mode: #d1d5db (good contrast)
  • Dark mode: #d1d5db (poor contrast against dark backgrounds)

After (text-gray-200)

  • Light mode: #e5e7eb (good contrast)
  • Dark mode: #e5e7eb (much better contrast against dark backgrounds)

Benefits

  1. Better Visibility: Text is now clearly visible in dark mode
  2. Improved Accessibility: Better contrast ratios for users with visual impairments
  3. Consistent Experience: Text displays consistently across all components
  4. Fallback Protection: Always shows content, even if processing fails
  5. User-Friendly: Clear indication when content is available

Testing Results

  • ✅ Text is now visible in dark mode
  • ✅ Better contrast against dark backgrounds
  • ✅ Fallback text appears when content is empty
  • ✅ Consistent behavior across all components
  • ✅ No impact on light mode functionality

Files Modified

  1. src/pages/home/Home.jsx

    • Updated text color from text-gray-300 to text-gray-200
    • Added fallback text for empty content
  2. src/pages/allBlogs/AllBlogs.jsx

    • Updated text color from text-gray-300 to text-gray-200
    • Added fallback text for empty content
  3. src/components/blogPostCard/BlogPostCard.jsx

    • Updated text color from text-gray-300 to text-gray-200
    • Added fallback text for empty content
  4. DARK_MODE_TEXT_VISIBILITY_FIX.md - This documentation file

Future Enhancements

  • Consider implementing dynamic contrast detection
  • Add user preference for text contrast
  • Implement high contrast mode for accessibility
  • Add text size adjustment options

The fix ensures that featured post text is clearly visible in both light and dark modes, providing a better user experience across all themes.