Skip to content

Fix icon button disabled state #48

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
20 changes: 19 additions & 1 deletion src/components/IconButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
:open-on-hover="tooltipOnHover"
:offset="tooltipOffset"
:disabled="!tooltipText || !showTooltip"
:class="['icon-button-v-tooltip', disabled ? 'disabled-tooltip' : '']"
>
<template v-slot:activator="{ props }: { props: Record<string,any> }">
<div
Expand All @@ -19,6 +20,7 @@
@touchend="handleTouchEnd"
:style="cssVars"
tabindex="0"
:aria-disabled="disabled"
>
<slot name="button">
<font-awesome-icon
Expand Down Expand Up @@ -64,7 +66,8 @@ const props = withDefaults(defineProps<IconButtonProps>(), {
tooltipOffset: 0,
showTooltip: true,
faSize: "lg",
mdSize: "1.25em"
mdSize: "1.25em",
disabled: false,
});

const emit = defineEmits<{
Expand Down Expand Up @@ -99,6 +102,9 @@ function updateValue() {
}

function handleAction() {
if (props.disabled) {
return;
}
updateValue();
emit('activate');
}
Expand Down Expand Up @@ -144,5 +150,17 @@ function handleTouchEnd() {
color: var(--active-color);
border-color: var(--active-color);
}

&[aria-disabled="true"]:hover {
cursor: not-allowed;
}
}

.icon-button-v-tooltip {

&.disabled-tooltip .v-overlay__content {
color: rgb(156, 156, 156); // fallback grey color for disabled state
color: color-mix(in hsl, currentColor, rgb(var(--v-theme-surface-variant)) 50%);
}
}
</style>
6 changes: 5 additions & 1 deletion src/stories/IconButton.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { IconButton } from "..";
import { library } from "@fortawesome/fontawesome-svg-core";
import { faBookOpen } from "@fortawesome/free-solid-svg-icons";

import "./stories.css";

library.add(faBookOpen);

const meta: Meta<typeof IconButton> = {
Expand Down Expand Up @@ -36,6 +38,7 @@ export const Primary: Story = {
mdIcon: null,
color: "white",
focusColor: "red",
activeColor: "green",
backgroundColor: "#040404",
boxShadow: true,
border: true,
Expand All @@ -47,6 +50,7 @@ export const Primary: Story = {
tooltipOnHover: true,
showTooltip: true,
faSize: "lg",
mdSize: "100px"
mdSize: "100px",
disabled: false,
}
};
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ export interface IconButtonProps {
faSize?: SizeType;
/** The size of the MDI icon. Should be a valid CSS size */
mdSize?: string;
/** Disable the button and prevent actions from running: Default is false */
disabled?: boolean;
}


Expand Down