Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds 'inactive' state to buttons #2283

Merged
merged 7 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/mean-bottles-unite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@primer/view-components": minor
---

Adds an 'inactive' state to buttons. An inactive button looks disabled and has aria-disabled, but it can still be clicked and focused. This was added to support buttons that are broken due to availability issues, but can't be removed from the page.

<!-- Changed components: Primer::Beta::Button, Primer::Beta::BaseButton, Primer::Beta::IconButton -->
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions app/components/primer/beta/base_button.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ class BaseButton < Primer::Component
# @param type [Symbol] <%= one_of(Primer::Beta::BaseButton::TYPE_OPTIONS) %>
# @param block [Boolean] Whether button is full-width with `display: block`.
# @param disabled [Boolean] Whether or not the button is disabled. If true, this option forces `tag:` to `:button`.
# @param inactive [Boolean] Whether the button looks visually disabled, but can still accept all the same interactions as an enabled button.
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
def initialize(
tag: DEFAULT_TAG,
type: DEFAULT_TYPE,
block: false,
disabled: false,
inactive: false,
**system_arguments
)
@system_arguments = system_arguments
Expand All @@ -37,6 +39,8 @@ def initialize(
"btn-block" => block
)

@system_arguments[:"aria-disabled"] = true if inactive

@disabled = disabled
return unless @disabled

Expand Down
8 changes: 6 additions & 2 deletions app/components/primer/beta/button.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,15 @@
transition: none;
}

&:disabled,
&[aria-disabled='true'] {
&:disabled {
cursor: not-allowed;
box-shadow: none;
}

&[aria-disabled='true'] {
cursor: default;
box-shadow: none;
}
}

.Button-withTooltip {
Expand Down
22 changes: 20 additions & 2 deletions previews/primer/beta/button_preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class ButtonPreview < ViewComponent::Preview
# @param size select [small, medium, large]
# @param block toggle
# @param disabled toggle
# @param inactive toggle
# @param align_content select [center, start]
# @param tag select [a, summary, button]
def playground(
Expand All @@ -27,7 +28,8 @@ def playground(
id: "button-preview",
align_content: :center,
tag: :button,
disabled: false
disabled: false,
inactive: false
)
render(Primer::Beta::Button.new(
scheme: scheme,
Expand All @@ -36,7 +38,8 @@ def playground(
id: id,
align_content: align_content,
tag: tag,
disabled: disabled
disabled: disabled,
inactive: inactive
)) do |_c|
"Button"
end
Expand Down Expand Up @@ -341,6 +344,21 @@ def with_tooltip(
align_content: align_content
})
end

# @label Inactive
# @param inactive toggle
# @snapshot
def inactive(
id: "button-preview",
inactive: true
)
render(Primer::Beta::Button.new(
id: id,
inactive: inactive
)) do |_c|
"Button"
end
end
end
end
end
3 changes: 3 additions & 0 deletions previews/primer/beta/icon_button_preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class IconButtonPreview < ViewComponent::Preview
# @param size select [small, medium, large]
# @param aria_label text
# @param disabled toggle
# @param inactive toggle
# @param tag select [a, summary, button]
# @param icon [Symbol] octicon
# @param show_tooltip toggle
Expand All @@ -18,6 +19,7 @@ def playground(
id: "button-preview",
tag: :button,
disabled: false,
inactive: false,
icon: :plus,
aria_label: "Button",
show_tooltip: true
Expand All @@ -28,6 +30,7 @@ def playground(
id: id,
tag: tag,
disabled: disabled,
inactive: inactive,
icon: icon,
"aria-label": aria_label,
show_tooltip: show_tooltip
Expand Down