Skip to content

Commit

Permalink
Correct the position of error text on the nimble-checkbox (#2486)
Browse files Browse the repository at this point in the history
# Pull Request

## 🤨 Rationale

The vertical spacing between the checkbox and its error text is
incorrect, so this PR is fixing it. According to [the visual design
spec](https://www.figma.com/design/PO9mFOu5BCl8aJvFchEeuN/Nimble_Components?node-id=1295-63171&node-type=frame&t=ODewc6hH8Cq1LC4n-0),
the error text on the checkbox should be 2px below the checkbox's height
(likely 32px or 24px based on the control height token). However, it was
incorrectly implemented to put the error text 2px below the checkbox
control (i.e. the square indicator).

## 👩‍💻 Implementation

Update the template & styling for the checkbox to position the
error-text correctly.

## 🧪 Testing

Manually tested
Verified chromatic diffs look correct

## ✅ Checklist

<!--- Review the list and put an x in the boxes that apply or ~~strike
through~~ around items that don't (along with an explanation). -->

- [x] I have updated the project documentation to reflect my changes or
determined no changes are needed.
  • Loading branch information
mollykreis authored Dec 4, 2024
1 parent 4ce5fa2 commit 4e192f9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Correct the position of error text on the nimble-checkbox",
"packageName": "@ni/nimble-components",
"email": "[email protected]",
"dependentChangeType": "patch"
}
11 changes: 8 additions & 3 deletions packages/nimble-components/src/checkbox/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@ import { userSelectNone } from '../utilities/style/user-select';
import { styles as errorStyles } from '../patterns/error/styles';

export const styles = css`
${display('inline-flex')}
${display('inline-grid')}
${errorStyles}
:host {
font: ${bodyFont};
align-items: center;
cursor: pointer;
outline: none;
${userSelectNone}
Expand All @@ -37,8 +36,14 @@ export const styles = css`
cursor: default;
}
.container {
.outer-container {
height: 100%;
display: flex;
align-items: center;
position: relative;
}
.container {
display: grid;
grid-template-columns: auto 1fr auto;
grid-template-rows: ${bodyFontLineHeight} auto;
Expand Down
40 changes: 21 additions & 19 deletions packages/nimble-components/src/checkbox/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,29 @@ CheckboxOptions
@click="${(x, c) => x.clickHandler(c.event as MouseEvent)}"
class="${x => (x.readOnly ? 'readonly' : '')} ${x => (x.checked ? 'checked' : '')} ${x => (x.indeterminate ? 'indeterminate' : '')}"
>
<div part="container" class="container">
<div part="control" class="control">
<slot name="checked-indicator">
${definition.checkedIndicator || ''}
</slot>
<slot name="indeterminate-indicator">
${definition.indeterminateIndicator || ''}
</slot>
</div>
<label
part="label"
class="${x => (x.defaultSlottedNodes?.length
<div class="outer-container">
<div part="container" class="container">
<div part="control" class="control">
<slot name="checked-indicator">
${definition.checkedIndicator || ''}
</slot>
<slot name="indeterminate-indicator">
${definition.indeterminateIndicator || ''}
</slot>
</div>
<label
part="label"
class="${x => (x.defaultSlottedNodes?.length
? 'label'
: 'label label__hidden')}"
>
<slot ${slotted('defaultSlottedNodes')}></slot>
</label>
<${iconExclamationMarkTag}
severity="error"
class="error-icon"
></${iconExclamationMarkTag}>
>
<slot ${slotted('defaultSlottedNodes')}></slot>
</label>
<${iconExclamationMarkTag}
severity="error"
class="error-icon"
></${iconExclamationMarkTag}>
</div>
${errorTextTemplate}
</div>
</template>
Expand Down

0 comments on commit 4e192f9

Please sign in to comment.