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

feat: apply hover effects anywhere on the component #3796

Merged
merged 6 commits into from
Jul 24, 2023
Merged
Changes from 4 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
18 changes: 11 additions & 7 deletions components/inputs/input-styles.js
dbatiste marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const inputStyles = css`
width: 100%;
}
.d2l-input,
.d2l-input:hover:disabled,
:host(:hover) .d2l-input:disabled,
.d2l-input:focus:disabled,
[aria-invalid="true"].d2l-input:disabled {
border-color: var(--d2l-input-border-color, var(--d2l-color-galena));
Expand All @@ -43,15 +43,19 @@ export const inputStyles = css`
font-size: 0.8rem;
font-weight: 400;
}
.d2l-input:hover,
:host(:hover) .d2l-input,
.d2l-input:focus,
.d2l-input-focus {
border-color: var(--d2l-color-celestine);
border-width: 2px;
outline-style: none;
outline-width: 0;
padding: var(--d2l-input-padding-focus, calc(0.4rem - 1px) calc(0.75rem - 1px));
}
:host(:hover) .d2l-input:not([aria-invalid="true"]),
Copy link
Contributor

Choose a reason for hiding this comment

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

Targeting :host(:hover) assumes that the consumer of these styles is a simple input component wrapper, not a component composed of multiple elements. I didn't dig into them but it does appear that app components are also consuming inputStyles directly. I think we need to assume they could be pulling those styles into a huge component composed of lots of different things, possibly even multiple inputs. Even if those cases are "ok" with this change, this does still make me feel a bit uneasy. I think it would be better if there was an element that we could target that would isolate this behaviour, like one of the wrapper divs. 🤔

Copy link
Member

Choose a reason for hiding this comment

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

Agreed. These input styles are intended to be used standalone on a <input class="d2l-input"> and as Dave mentioned the "host" may be a much larger component composed of many different things.

I think if we want to do this it'll have to be something constrained to <d2l-input-text>, which is the thing that knows about the label. We may need to programatically add/remove a .d2l-input-hover CSS class when the host is hovered/blurred, and then add CSS here to handle it -- similar to how this already understands .d2l-input-focus.

.d2l-input:focus,
.d2l-input-focus {
border-color: var(--d2l-color-celestine);
}
[aria-invalid="true"].d2l-input {
border-color: var(--d2l-color-cinnabar);
}
Expand All @@ -71,13 +75,13 @@ export const inputStyles = css`
line-height: normal;
}
textarea.d2l-input,
textarea.d2l-input:hover:disabled,
:host(:hover) textarea.d2l-input:disabled,
textarea.d2l-input:focus:disabled,
textarea[aria-invalid="true"].d2l-input:disabled {
padding-bottom: 0.5rem;
padding-top: 0.5rem;
}
textarea.d2l-input:hover,
:host(:hover) textarea.d2l-input,
textarea.d2l-input:focus {
padding: var(--d2l-input-padding-focus, calc(0.75rem - 1px));
padding-bottom: calc(0.5rem - 1px);
Expand All @@ -90,7 +94,7 @@ export const inputStyles = css`
background-size: 0.8rem 0.8rem;
padding-right: calc(18px + 0.8rem);
}
textarea.d2l-input[aria-invalid="true"]:hover,
:host(:hover) textarea.d2l-input[aria-invalid="true"],
textarea.d2l-input[aria-invalid="true"]:focus {
background-position: top calc(12px - 1px) right calc(18px - 1px);
padding-right: calc(18px + 0.8rem - 1px);
Expand All @@ -103,7 +107,7 @@ export const inputStyles = css`
padding-top: 0.5rem;
}
:host([dir='rtl']) textarea.d2l-input[aria-invalid="true"]:focus,
:host([dir='rtl']) textarea.d2l-input[aria-invalid="true"]:hover {
:host([dir='rtl']:hover) textarea.d2l-input[aria-invalid="true"] {
background-position: top calc(12px - 1px) left calc(18px - 1px);
padding: var(--d2l-input-padding-focus, calc(0.75rem - 1px));
padding-bottom: calc(0.5rem - 1px);
Expand Down