Skip to content

Commit

Permalink
fix: icon abandoning parent (#2699)
Browse files Browse the repository at this point in the history
resolves #2696

This PR makes `hideLabel` work weird in some form components. This will
be looked at when we refactor these, as this has not been done yet. The
position relative we added makes our `sr-only` class not set its
position absolute.
  • Loading branch information
Barsnes authored Oct 31, 2024
1 parent 7058b69 commit c43a438
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/blue-stingrays-heal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@digdir/designsystemet-css": patch
---

Accordion: Fix chevron abandoning parent in scroll container
5 changes: 5 additions & 0 deletions .changeset/slow-impalas-vanish.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@digdir/designsystemet-css": patch
---

Label: Fix icon abandoning parent in scroll container
1 change: 1 addition & 0 deletions packages/css/accordion.css
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
gap: var(--dsc-accordion-chevron-gap);
outline: none;
padding: var(--dsc-accordion-padding);
position: relative;

@composes ds-focus from './base/base.css';

Expand Down
1 change: 1 addition & 0 deletions packages/css/label.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

font-weight: var(--ds-font-weight-medium);
padding-inline-start: var(--dsc-label--readonly) calc(var(--dsc-label-icon-size) + var(--dsc-label-gap));
position: relative;

&::before {
background: currentcolor;
Expand Down
6 changes: 3 additions & 3 deletions packages/react/src/components/form/Search/Search.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('Search', () => {
expect(screen.getByDisplayValue('test')).toBeDefined();
});

test('has correct label when label is hidden', () => {
test('has correct aria-label when hiding label', () => {
render({ label: 'label', hideLabel: true });

expect(screen.getByLabelText('label')).toBeDefined();
Expand Down Expand Up @@ -48,14 +48,14 @@ describe('Search', () => {

it('Focuses on search field when label is clicked and id is not given', async () => {
const label = 'Lorem ipsum';
const { user } = render({ label });
const { user } = render({ label, hideLabel: false });
await act(async () => await user.click(screen.getByText(label)));
expect(screen.getByRole('searchbox')).toHaveFocus();
});

it('Focuses on search field when label is clicked and id is given', async () => {
const label = 'Lorem ipsum';
const { user } = render({ id: 'some-unique-id', label });
const { user } = render({ id: 'some-unique-id', label, hideLabel: false });
await act(async () => await user.click(screen.getByText(label)));
expect(screen.getByRole('searchbox')).toHaveFocus();
});
Expand Down
3 changes: 2 additions & 1 deletion packages/react/src/components/form/Search/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export const Search = forwardRef<HTMLInputElement, SearchProps>(
className,
)}
>
{label && (
{!hideLabel && (
<Label
data-size={size}
weight='medium'
Expand Down Expand Up @@ -148,6 +148,7 @@ export const Search = forwardRef<HTMLInputElement, SearchProps>(
{...omit(['size', 'error', 'errorId', 'readOnly'], rest)}
{...inputProps}
onChange={handleChange}
aria-label={hideLabel ? label?.toString() : undefined}
/>
{showClearButton && (
<button
Expand Down

0 comments on commit c43a438

Please sign in to comment.