Course contentsShow
← Web Development
Lesson 1655 of 2,98230. Web Authorization PatternsFree lesson

Action Button States

Manage button states for create, edit, delete actions based on granular permissions.

Action Button States

You'll learn how to dynamically manage the enabled, disabled, and visibility states of action buttons based on a user's granular permissions.

Why Button States Matter

In permission-based interfaces, not all users should see or interact with every action. A "Delete" button should be disabled (or hidden) if the user lacks resource:delete permission. A "Publish" button might only appear for users with content:publish. Managing these states creates intuitive, secure interfaces that guide users toward actions they're actually allowed to perform.

Core Patterns for Action Buttons

Disabled State: The button is visible but grayed out and unresponsive. Use this when you want users to know an action exists but understand they can't perform it:

<button 
  disabled={!hasPermission('post:delete')}
  onClick={handleDelete}
>
  Delete Post
</button>

Hidden State: The button doesn't render at all. Use this for sensitive actions where even revealing the option could expose information:

{hasPermission('user:ban') && (
  <button onClick={handleBan}>Ban User</button>
)}

Visual Feedback: Combine both approaches—show disabled buttons for common actions, hide buttons for privileged ones:

<button 
  disabled={!hasPermission('post:edit')}
  title={!hasPermission('post:edit') ? 'You lack edit permissions' : ''}
>
  Edit
</button>

{hasPermission('post:delete') && (
  <button onClick={handleDelete}>Delete</button>
)}

Context-Aware States

Button states often depend on both permissions and resource ownership:

const canEdit = hasPermission('post:edit') || isOwner;
const canDelete = hasPermission('post:delete') && !post.published;

<button disabled={!canEdit}>Edit</button>
<button disabled={!canDelete}>Delete</button>

Key Takeaway: Action button states should reflect users' actual permissions—use disabled buttons for transparency about unavailable actions, hidden buttons for sensitive operations, and combine both for intuitive, secure interfaces.