Skip to content

Commit

Permalink
trim jsdoc comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jamieomaguire committed Dec 16, 2024
1 parent e78ae75 commit d32333e
Showing 1 changed file with 1 addition and 105 deletions.
106 changes: 1 addition & 105 deletions packages/components/pie-radio-group/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,6 @@ export class PieRadioGroup extends FormControlMixin(RtlMixin(LitElement)) implem
/**
* Tracks whether the `Shift` key was held during the last `Tab` key press.
*
* This static property is updated whenever a `Tab` key press is detected. It is used
* to determine navigation direction when the radio group gains focus:
* - `true`: Indicates that the user pressed `Shift+Tab` for backward navigation.
* - `false`: Indicates that the user pressed `Tab` alone for forward navigation.
*
* The property is static because it needs to be shared across all instances of the
* `PieRadioGroup` component on the same page, ensuring consistent behavior.
*/
Expand Down Expand Up @@ -186,17 +181,6 @@ export class PieRadioGroup extends FormControlMixin(RtlMixin(LitElement)) implem

/**
* Updates the state of `_wasShiftTabPressed` based on the last `Tab` key press.
*
* When a `Tab` key press is detected, this method updates the static property
* `wasShiftTabPressed` to indicate whether the `Shift` key was also held during
* the event. This information is used to manage focus direction when the radio
* group gains focus.
*
* @param {KeyboardEvent} event - The keyboard event containing information about the key press.
*
* Example Usage:
* - If `Shift+Tab` is pressed, `_wasShiftTabPressed` is set to `true` to signal backward navigation.
* - If `Tab` alone is pressed, `_wasShiftTabPressed` is set to `false` for forward navigation.
*/
private _updateShiftTabState (event: KeyboardEvent): void {
if (event.key === 'Tab') {
Expand All @@ -210,21 +194,6 @@ export class PieRadioGroup extends FormControlMixin(RtlMixin(LitElement)) implem
* This method determines the appropriate element to focus when the radio group
* gains focus. It considers the last navigation action (whether `Shift+Tab` was used)
* and focuses the checked option, the first option, or the last option as needed.
*
* **Behaviour:**
* - If the event target is the radio group itself:
* - If an option is already checked, it focuses the checked option.
* - If `Shift+Tab` was pressed, it focuses the last option.
* - Otherwise, it focuses the first option.
* - It disables the `tabindex` on the radio group's `fieldset` to allow focus to remain on
* the appropriate option.
*
* @param {FocusEvent} event - The focus event triggered when the radio group gains focus.
*
* Example Usage:
* - When the user navigates to the radio group using `Shift+Tab`, the last option is focused.
* - When the user navigates using `Tab`, the first option is focused (unless one is checked).
* - If an option is already checked, it takes precedence and is focused.
*/
private _handleFocusIn (event: FocusEvent): void {
if (this !== event.target) return;
Expand All @@ -245,26 +214,11 @@ export class PieRadioGroup extends FormControlMixin(RtlMixin(LitElement)) implem
* When focus leaves the radio group, this method enables the `tabindex` attribute
* on the `fieldset` element. This ensures the radio group remains accessible for
* keyboard navigation and can be re-focused when tabbing back into the group.
*
*/
private _handleFocusOut (): void {
this._toggleFieldsetTabindex(true);
}

/**
* Toggles the `tabindex` attribute on the radio group's `fieldset` element.
*
* This method enables or disables the `tabindex` on the `fieldset` element based on
* the provided `enable` flag. Enabling the `tabindex` allows the radio group to be
* focusable via keyboard navigation, while disabling it prevents the `fieldset` from
* interfering with the focus management of its child options.
*
* **Example Usage:**
* - When the radio group loses focus, `_toggleFieldsetTabindex(true)` ensures the group is focusable.
* - When a specific radio option is focused, `_toggleFieldsetTabindex(false)` prevents accidental focus on the `fieldset`.
*
* @param {boolean} enable - Whether to enable (`true`) or disable (`false`) the `tabindex` on the `fieldset`.
*/
private _toggleFieldsetTabindex (enable: boolean): void {
if (enable) {
this._fieldset.setAttribute('tabindex', '0');
Expand All @@ -273,21 +227,6 @@ export class PieRadioGroup extends FormControlMixin(RtlMixin(LitElement)) implem
}
}

/**
* Moves focus within the radio group to the next or previous option.
*
* This method calculates the new index of the option to focus based on the
* current index and a directional step. It wraps around when the focus reaches
* the first or last option.
* Once the target option is determined, it focuses and triggers a click event on it.
*
* **Example Usage:**
* - If the current index is `0` and `step` is `1`, the next option (index `1`) will be focused.
* - If the current index is the last option and `step` is `1`, focus wraps to the first option.
*
* @param {number} currentIndex - The index of the currently focused option.
* @param {number} step - The directional step to move the focus (e.g., `1` for forward, `-1` for backward).
*/
private _moveFocus (currentIndex: number, step: number): void {
const newIndex = (currentIndex + step + this._slottedChildren.length) % this._slottedChildren.length;
this._focusAndClickOption(this._slottedChildren[newIndex]);
Expand All @@ -304,13 +243,6 @@ export class PieRadioGroup extends FormControlMixin(RtlMixin(LitElement)) implem
* - `ArrowRight` and `ArrowDown` indicate forward navigation.
* - For RTL (Right-to-Left) layouts:
* - `ArrowLeft` and `ArrowDown` indicate forward navigation.
*
* **Example Usage:**
* - In an LTR layout, pressing `ArrowRight` or `ArrowDown` returns `true`.
* - In an RTL layout, pressing `ArrowLeft` or `ArrowDown` returns `true`.
*
* @param {KeyboardEvent} event - The keyboard event containing information about the key press.
* @returns {boolean} `true` if the key press is for forward navigation; otherwise, `false`.
*/
private _isForwardKey (event: KeyboardEvent): boolean {
return (event.code === 'ArrowRight' && !this.isRTL) ||
Expand All @@ -329,13 +261,6 @@ export class PieRadioGroup extends FormControlMixin(RtlMixin(LitElement)) implem
* - `ArrowLeft` and `ArrowUp` indicate backward navigation.
* - For RTL (Right-to-Left) layouts:
* - `ArrowRight` and `ArrowUp` indicate backward navigation.
*
* **Example Usage:**
* - In an LTR layout, pressing `ArrowLeft` or `ArrowUp` returns `true`.
* - In an RTL layout, pressing `ArrowRight` or `ArrowUp` returns `true`.
*
* @param {KeyboardEvent} event - The keyboard event containing information about the key press.
* @returns {boolean} `true` if the key press is for backward navigation; otherwise, `false`.
*/
private _isBackwardKey (event: KeyboardEvent): boolean {
return (event.code === 'ArrowLeft' && !this.isRTL) ||
Expand All @@ -349,19 +274,6 @@ export class PieRadioGroup extends FormControlMixin(RtlMixin(LitElement)) implem
* This method responds to `keydown` events and determines the appropriate navigation
* action (forward or backward) based on the pressed key and the current focus. It prevents
* the default browser behaviour (e.g., scrolling) when arrow keys are used for navigation.
*
* **Behaviour:**
* - Checks if the currently focused element is one of the radio group options.
* - Determines the index of the currently focused option.
* - Prevents default scrolling behavior if an arrow key (`ArrowRight`, `ArrowDown`, `ArrowLeft`, `ArrowUp`) is pressed.
* - Uses `_isForwardKey` or `_isBackwardKey` to determine the navigation direction and calls `_moveFocus` to update focus.
*
* **Example Usage:**
* - Pressing `ArrowRight` (in LTR) moves the focus to the next option.
* - Pressing `ArrowLeft` (in RTL) moves the focus to the next option.
* - Pressing `ArrowUp` or `ArrowDown` navigates backward or forward, respectively, regardless of text direction.
*
* @param {KeyboardEvent} event - The keyboard event containing information about the key press.
*/
private _handleKeyDown (event: KeyboardEvent): void {
const currentlyFocusedChild = this._slottedChildren.find((child) => child === document.activeElement);
Expand All @@ -387,22 +299,6 @@ export class PieRadioGroup extends FormControlMixin(RtlMixin(LitElement)) implem
}
}

/**
* Focuses a radio option and triggers a `click` event to ensure proper behaviour.
*
* This method sets focus on the provided radio option and programmatically triggers
* a `click` event on its underlying `<input>` element. The `click` event ensures
* that the radio group emits a `change` event as expected. Additionally,
* it disables the `fieldset`'s `tabindex` to maintain proper focus behavior.
*
* **Behaviour:**
* - Sets focus on the provided `option`.
* - Finds the corresponding `<input>` element within the `option`'s shadow DOM (if available)
* and triggers a `click` event.
* - Disables the `tabindex` on the `fieldset` to ensure focus remains on the option.
*
* @param {HTMLInputElement} option - The radio option to focus and click.
*/
private _focusAndClickOption (option: HTMLInputElement): void {
option.focus();
// This is quite hacky, but it ensures the radio elements correct emit a real change event.
Expand All @@ -414,7 +310,7 @@ export class PieRadioGroup extends FormControlMixin(RtlMixin(LitElement)) implem

disconnectedCallback (): void {
super.disconnectedCallback();
this._abortController.abort(); // This automatically removes event listeners associated with the signal
this._abortController.abort();
}

render () {
Expand Down

0 comments on commit d32333e

Please sign in to comment.