-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(sbb-header): shows the header if it has visible focus within (#2237)
- Loading branch information
1 parent
ca643e7
commit 37061ad
Showing
11 changed files
with
154 additions
and
35 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
src/components/core/a11y/focus-visible-within-controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { ReactiveController, ReactiveControllerHost } from 'lit'; | ||
|
||
import { toggleDatasetEntry } from '../dom'; | ||
|
||
import { sbbInputModalityDetector } from './input-modality-detector'; | ||
|
||
// Determine whether the element has a visible focus within. | ||
export class FocusVisibleWithinController implements ReactiveController { | ||
private _focusinHanlder = (): void => { | ||
toggleDatasetEntry( | ||
this._host, | ||
'hasVisibleFocusWithin', | ||
sbbInputModalityDetector.mostRecentModality === 'keyboard', | ||
); | ||
}; | ||
|
||
private _focusoutHanlder = (): void => { | ||
toggleDatasetEntry(this._host, 'hasVisibleFocusWithin', false); | ||
}; | ||
|
||
public constructor(private _host: ReactiveControllerHost & HTMLElement) { | ||
this._host.addController(this); | ||
} | ||
|
||
public hostConnected(): void { | ||
this._host.addEventListener('focusin', this._focusinHanlder); | ||
this._host.addEventListener('focusout', this._focusoutHanlder); | ||
} | ||
|
||
public hostDisconnected(): void { | ||
this._host.removeEventListener('focusin', this._focusinHanlder); | ||
this._host.removeEventListener('focusout', this._focusoutHanlder); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
export * from './arrow-navigation'; | ||
export * from './assign-id'; | ||
export * from './fake-event-detection'; | ||
export * from './focus-visible-within-controller'; | ||
export * from './focus'; | ||
export * from './interactivity-checker'; | ||
export * from './input-modality-detector'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.