Skip to content

Fleet UI: Users can see a tooltip on a disabled checkbox #17664

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

Merged
merged 6 commits into from
Mar 26, 2024
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
1 change: 1 addition & 0 deletions changes/16345-disabled-checkbox-tooltip
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- UI fix: users can see a tooltip on a disabled checkbox
17 changes: 11 additions & 6 deletions frontend/components/forms/fields/Checkbox/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,26 @@ const Checkbox = (props: ICheckboxProps) => {
className,
baseClass
);

const checkBoxTickClass = classnames(`${baseClass}__tick`, {
[`${baseClass}__tick--disabled`]: disabled,
[`${baseClass}__tick--indeterminate`]: indeterminate,
});

const checkBoxLabelClass = classnames(checkBoxClass, {
[`${baseClass}__label--disabled`]: disabled,
});

const formFieldProps = {
...pick(props, ["helpText", "label", "error", "name"]),
className: wrapperClassName,
type: "checkbox",
} as IFormFieldProps;

const checkBoxTickClass = classnames(`${checkBoxClass}__tick`, {
[`${checkBoxClass}__tick--disabled`]: disabled,
[`${checkBoxClass}__tick--indeterminate`]: indeterminate,
});

return (
<FormField {...formFieldProps}>
<>
<label htmlFor={name} className={checkBoxClass}>
<label htmlFor={name} className={checkBoxLabelClass}>
<input
checked={value}
className={`${baseClass}__input`}
Expand Down
17 changes: 17 additions & 0 deletions frontend/components/forms/fields/Checkbox/_styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@
}
}

&--disabled {
&::after {
@include disabled-checkbox;
}

&:hover {
&::after {
@include disabled-checkbox;
}
}
}

&::before {
@include position(absolute, 50% null null 50%);
transform: rotate(45deg);
Expand All @@ -41,6 +53,7 @@
border-top: 0;
border-left: 0;
content: "";
z-index: 9;
}
}
}
Expand Down Expand Up @@ -109,6 +122,10 @@
padding-left: $pad-small;
display: inline-block;
vertical-align: top;

&--disabled {
color: $ui-fleet-black-50;
}
}

&__label-tooltip {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,32 +48,26 @@ const TeamHostExpiryToggle = ({
<Checkbox
name="enableHostExpiry"
onChange={setTeamExpiryEnabled}
value={teamExpiryEnabled || globalHostExpiryEnabled}
wrapperClassName={
globalHostExpiryEnabled
? `${baseClass}__disabled-team-host-expiry-toggle`
: ""
}
value={teamExpiryEnabled || globalHostExpiryEnabled} // Still shows checkmark if global expiry is enabled though the checkbox will be disabled.
disabled={globalHostExpiryEnabled}
helpText={renderHelpText()}
tooltipContent={
!globalHostExpiryEnabled && (
<>
When enabled, allows automatic cleanup of
<>
When enabled, allows automatic cleanup of
<br />
hosts that have not communicated with Fleet in
<br />
the number of days specified in the{" "}
<strong>
Host expiry
<br />
hosts that have not communicated with Fleet in
<br />
the number of days specified in the{" "}
<strong>
Host expiry
<br />
window
</strong>{" "}
setting.{" "}
<em>
(Default: <strong>Off</strong>)
</em>
</>
)
window
</strong>{" "}
setting.{" "}
<em>
(Default: <strong>Off</strong>)
</em>
</>
}
>
Enable host expiry
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
.team-host-expiry-toggle {
&__disabled-team-host-expiry-toggle > .fleet-checkbox {
@include disabled;
}

&__add-custom-window {
display: inline-flex;
align-items: center;
Expand Down
7 changes: 7 additions & 0 deletions frontend/styles/var/mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,13 @@ $max-width: 2560px;
cursor: default;
}

@mixin disabled-checkbox {
background-color: $ui-fleet-black-25;
border-color: $ui-fleet-black-25;
pointer-events: none;
cursor: default;
}

@mixin grey-text {
color: $ui-fleet-black-75;
}
Expand Down