Skip to content

Feature/floating labels#11

Open
hyosua wants to merge 5 commits into
clementbouly:mainfrom
hyosua:feature/floating-labels
Open

Feature/floating labels#11
hyosua wants to merge 5 commits into
clementbouly:mainfrom
hyosua:feature/floating-labels

Conversation

@hyosua
Copy link
Copy Markdown

@hyosua hyosua commented Dec 27, 2025

feat: Implement and demonstrate Floating Labels for improved form UX

This PR introduces the "Floating Label" pattern, providing a robust and accessible alternative to placeholder-only inputs, especially in forms.

Why Floating Labels?

Placeholder-only inputs can lead to significant usability and accessibility issues:

  • Reduces Cognitive Load: If a user gets distracted or looks away, they return to a field filled with **** and no context. Persistent labels prevent this frustration.
  • Prevents Errors: By keeping the label visible, users can confidently verify they are typing the correct information.
  • Improves Mobile Experience: On mobile devices, the virtual keyboard often obscures part of the screen. Losing the label inside the field makes it even harder to track progress through a form.
  • Accessibility: Screen readers often struggle with placeholders, and once a value is entered, the contextual hint is gone. Floating labels maintain a clear association with the input.

What's Included:

  • FloatingInput Component: A new reusable React component (src/components/FloatingInput.jsx) that implements the floating label behavior using Tailwind CSS.
  • Bad Example (BadExample.tsx): Demonstrates the common pitfalls of relying solely on placeholders, especially for similar fields like password confirmation.
  • Good Example (GoodExample.tsx): Showcases the FloatingInput component in action, including integrated password visibility toggles, highlighting best practices.
  • Comprehensive Documentation (README.md): A detailed explanation of floating labels, their benefits, and guidance on when to apply or avoid this pattern.
  • Example Integration: Updates to src/examples/floating-label/index.ts to make these examples discoverable within our component library/showcase.
image

This commit introduces a new UI example demonstrating the importance of visible labels over relying solely on placeholders in form inputs. It includes both a bad example (placeholder as label) and a good example (explicit label with password visibility toggle).

- Adds new components (`BadExample.tsx`, `GoodExample.tsx`) for the "Visible Label" pattern.
- Integrates the new example into the `src/examples/index.ts`.
Introduces a reusable `FloatingInput` component and an example demonstrating the floating label pattern. This pattern improves form accessibility and usability by keeping labels visible even when input fields are populated.
@netlify
Copy link
Copy Markdown

netlify Bot commented Dec 27, 2025

Deploy Preview for ux-good-patterns failed.

Name Link
🔨 Latest commit 23aea91
🔍 Latest deploy log https://app.netlify.com/projects/ux-good-patterns/deploys/69500b2494af8a000890f5de

@hyosua
Copy link
Copy Markdown
Author

hyosua commented Dec 27, 2025

It looks like the Netlify deploy preview failed during the repo preparation step:
fatal: unable to access github.com (Could not resolve host)

This seems to be a Netlify/GitHub connectivity issue rather than a code problem.
Let me know if you want me to rebase or push again.

image

@clementbouly
Copy link
Copy Markdown
Owner

clementbouly commented Jan 30, 2026

Salut @hyosua ! 👋

Désolé pour la review tardive – je n'avais pas vu ta PR, je viens seulement de la remarquer. My bad ! 🙈

C'est une super contribution ! Merci d'avoir pris le temps d'ajouter ça au projet !

En y réfléchissant, je me dis juste qu'on pourrait rendre l'exemple encore plus utile en le reframant légèrement :

Renommer en "Always keep labels visible" (ou "Ne jamais masquer les labels") — ça couvre le problème de fond.

Et proposer deux variantes dans les good examples :

  1. Label statique (Recommended) — la solution la plus simple et accessible
  2. Floating label — ton composant actuel, comme alternative plus stylée

Pour contexte : les floating labels ont été popularisés par Material Design surtout pour des raisons esthétiques (gain de place), mais des experts UX comme Nielsen Norman Group recommandent plutôt les labels statiques pour leur simplicité et accessibilité. Montrer les deux permet d'être complet !

Comme ça on montre qu'il y a plusieurs façons de résoudre le problème, tout en recommandant la plus simple. Ton travail sur le floating label est conservé et utile !

Qu'est-ce que tu en penses ?


Niveau code : Quelques ajustements nécessaires

Comme un mois s'est écoulé, il y a eu des changements sur le repo. Il faudra rebase sur main et faire les modifications suivantes :

1. Supprimer les fichiers non liés

  • .astro/types.d.ts → ce dossier est maintenant dans le gitignore
  • package-lock.json → ces changements semblent être du bruit (pas de nouvelles dépendances)

2. Convertir en TypeScript

  • FloatingInput.jsx → devrait être FloatingInput.tsx avec des props typées (tout le projet est en TypeScript)

3. Utiliser les variables du design system

Les couleurs en dur ne fonctionneront pas bien avec le dark mode :

- text-amber-700
- text-gray-500
+ text-primary
+ text-muted-foreground

4. Corriger l'attribut autocomplete

- autoComplete={placeholder}
+ autoComplete="new-password" // ou la valeur appropriée

(autoComplete attend des valeurs standardisées comme "new-password", pas le texte du placeholder)

5. Ajouter le support i18n

Le projet supporte maintenant le français. Il faudra ajouter :

  • Les traductions dans src/i18n/examples.ts (regarde les autres exemples pour le format)
  • Un fichier README.fr.md

6. Ajouter aiSummary au meta

export const meta = {
  // ...champs existants
  aiSummary: "Use floating labels instead of placeholder-only inputs..."
};

7. Déplacer le composant

FloatingInput.tsx devrait être dans src/examples/floating-label/ plutôt que dans src/components/ car il est spécifique à cet exemple.

8. Conventions mineures

  • Utiliser export function BadExample() au lieu de export const BadExample = () => pour matcher le style du codebase

N'hésite pas si tu as des questions ou besoin d'aide pour le rebase ! Hâte de merger ça 🚀

Comment thread .astro/types.d.ts
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ne doit plus être commit

placeholder={placeholder}
name={id}
type={type}
autoComplete={placeholder}
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

L'attribut autoComplete attend des valeurs standardisées comme :

  • "new-password" - pour un nouveau mot de passe
  • "current-password" - pour un mot de passe existant
  • "email", "username", "tel", etc.

Là, il passe le texte du placeholder (ex: "Enter your new password") ce qui n'est pas une valeur valide. Le navigateur ignorera
cette valeur et l'autocomplétion ne fonctionnera pas correctement.

https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Attributes/autocomplete#specifications

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FIchier à mettre en tsx avec typage si possible

/>
<label
htmlFor={id}
className="absolute -top-4 left-0 text-xs text-amber-700 transition-all
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Les couleurs en dur ne fonctionneront pas bien avec le dark mode :

- text-amber-700
- text-gray-500
+ text-primary
+ text-muted-foreground

category: "Forms",
tags: ["accessibility", "forms", "labels", "placeholders"],
createdAt: "2025-12-22",
};
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ajouter aiSummary au meta

export const meta = {
// ...champs existants
aiSummary: "Use floating labels instead of placeholder-only inputs..."
};

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FloatingInput.tsx devrait être dans src/examples/floating-label/ plutôt que dans src/components/ car il est spécifique à cet exemple.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants