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

2017 - fix ic-toggle-button-group props not getting passed down to ic-toggle-buttons #2817

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion packages/web-components/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1393,7 +1393,7 @@ export namespace Components {
/**
* @param setFocusToAnchor when true return focus to anchor element when menu is closed
*/
"closeMenu": (setFocusToAnchor?: boolean, element?: HTMLIcMenuItemElement) => Promise<void>;
"closeMenu": (setFocusToAnchor?: boolean, menuElement?: HTMLIcMenuItemElement) => Promise<void>;
/**
* If `true`, the popover menu will be displayed.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
Event,
EventEmitter,
State,
Watch,
forceUpdate,
} from "@stencil/core";
import {
IcSizes,
Expand Down Expand Up @@ -87,6 +89,24 @@ export class ToggleButtonGroup {
*/
@Prop({ reflect: true }) variant: "default" | "icon" = "default";

@Watch("variant")
watchVariantHandler(newValue: "default" | "icon"): void {
this.getAllToggleButtons().forEach(
(toggleButton) => (toggleButton.variant = newValue)
);
}

@Watch("loading")
@Watch("size")
@Watch("appearance")
@Watch("disabled")
@Watch("iconPlacement")
watchPropsHandler(): void {
this.getAllToggleButtons().forEach((toggleButton) =>
forceUpdate(toggleButton)
);
}

/**
* Emitted when a toggle button is selected.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@

:host(.expand-toggle-group-child) ::part(button) {
width: 100%;
min-height: inherit;
min-height: max-content;
white-space: inherit;
height: inherit;
}

:host ic-button {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { IcSizes, IcThemeForeground } from "../../utils/types";
export class ToggleButton {
private iconPosition: "left" | "right" | "top";
private hostMutationObserver: MutationObserver = null;
private parentGroup?: HTMLIcToggleButtonGroupElement;

@Element() el: HTMLIcToggleButtonElement;

Expand Down Expand Up @@ -94,10 +95,9 @@ export class ToggleButton {
componentWillLoad(): void {
removeDisabledFalse(this.disabled, this.el);

const parentIconPlacement = (
this.el.parentElement as HTMLIcToggleButtonGroupElement
).iconPlacement;
this.iconPosition = this.iconPlacement || parentIconPlacement;
this.parentGroup = this.getParentToggleGroup();

this.iconPosition = this.iconPlacement ?? this.parentGroup?.iconPlacement;
}

componentDidLoad(): void {
Expand Down Expand Up @@ -135,9 +135,9 @@ export class ToggleButton {

@Listen("click", { capture: true })
handleHostClick(e: Event): void {
if (this.disabled) {
if (this.disabled || this.parentGroup?.disabled) {
e.stopImmediatePropagation();
} else if (!this.loading) {
} else if (!(this.loading || this.parentGroup?.loading)) {
this.toggleChecked = !this.toggleChecked;
}
}
Expand All @@ -146,9 +146,16 @@ export class ToggleButton {
ev.stopImmediatePropagation();
};

private getParentToggleGroup = (): HTMLIcToggleButtonGroupElement | null => {
if (this.el.parentElement.nodeName === "IC-TOGGLE-BUTTON-GROUP") {
return this.el.parentElement as HTMLIcToggleButtonGroupElement;
}
return null;
};

private handleClick = (): void => {
!this.loading &&
!this.disabled &&
!(this.loading || this.parentGroup?.loading) &&
!(this.disabled || this.parentGroup?.disabled) &&
this.icToggleChecked.emit({
checked: this.toggleChecked,
});
Expand All @@ -158,12 +165,12 @@ export class ToggleButton {
return (
<Host
class={{
["disabled"]: this.disabled,
["disabled"]: this.disabled || this.parentGroup?.disabled,
["checked"]: this.toggleChecked,
[`${this.appearance}`]: true,
[`${this.parentGroup?.appearance ?? this.appearance}`]: true,
["icon"]: this.variant === "icon",
[`${this.size}`]: true,
["loading"]: this.loading,
[`${this.parentGroup?.size ?? this.size}`]: true,
["loading"]: this.loading || this.parentGroup?.loading,
}}
onFocus={this.handleFocus}
>
Expand All @@ -175,11 +182,11 @@ export class ToggleButton {
aria-label={`${
this.accessibleLabel ? this.accessibleLabel : this.label
}, ${this.toggleChecked ? "ticked" : "unticked"}`}
disabled={this.disabled}
appearance={this.appearance}
size={this.size}
disabled={this.disabled || this.parentGroup?.disabled}
appearance={this.parentGroup?.appearance ?? this.appearance}
size={this.parentGroup?.size ?? this.size}
fullWidth={this.fullWidth}
loading={this.loading}
loading={this.loading || this.parentGroup?.loading}
aria-disabled={`${this.disabled}`}
>
{this.variant !== "icon" && this.label}
Expand Down
Loading