q2-tecton-elements 1.54.3 → 1.54.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle-report.json +100 -19
- package/dist/cjs/q2-badge_7.cjs.entry.js +13 -5
- package/dist/cjs/q2-badge_7.cjs.entry.js.map +1 -1
- package/dist/cjs/q2-dropdown-item.cjs.entry.js +21 -2
- package/dist/cjs/q2-dropdown-item.cjs.entry.js.map +1 -1
- package/dist/cjs/q2-file-picker.cjs.entry.js +1 -1
- package/dist/cjs/q2-file-picker.cjs.entry.js.map +1 -1
- package/dist/cjs/q2-option-list_2.cjs.entry.js +7 -5
- package/dist/cjs/q2-option-list_2.cjs.entry.js.map +1 -1
- package/dist/cjs/q2-option.cjs.entry.js +15 -1
- package/dist/cjs/q2-option.cjs.entry.js.map +1 -1
- package/dist/collection/components/q2-btn/q2-btn.css +56 -51
- package/dist/collection/components/q2-btn/q2-btn.js +12 -4
- package/dist/collection/components/q2-btn/q2-btn.js.map +1 -1
- package/dist/collection/components/q2-dropdown/test/q2-dropdown-test.e2e.js +38 -2
- package/dist/collection/components/q2-dropdown/test/q2-dropdown-test.e2e.js.map +1 -1
- package/dist/collection/components/q2-dropdown-item/q2-dropdown-item.js +21 -2
- package/dist/collection/components/q2-dropdown-item/q2-dropdown-item.js.map +1 -1
- package/dist/collection/components/q2-dropdown-item/test/q2-dropdown-item-test.e2e.js +43 -2
- package/dist/collection/components/q2-dropdown-item/test/q2-dropdown-item-test.e2e.js.map +1 -1
- package/dist/collection/components/q2-file-picker/q2-file-picker.css +1 -1
- package/dist/collection/components/q2-option/q2-option.js +29 -1
- package/dist/collection/components/q2-option/q2-option.js.map +1 -1
- package/dist/collection/components/q2-option/test/q2-option-test.e2e.js +33 -114
- package/dist/collection/components/q2-option/test/q2-option-test.e2e.js.map +1 -1
- package/dist/collection/components/q2-option-list/q2-option-list.js +7 -5
- package/dist/collection/components/q2-option-list/q2-option-list.js.map +1 -1
- package/dist/collection/utils/mirror-emit.js +19 -0
- package/dist/collection/utils/mirror-emit.js.map +1 -0
- package/dist/components/q2-btn2.js +13 -5
- package/dist/components/q2-btn2.js.map +1 -1
- package/dist/components/q2-dropdown-item2.js +21 -2
- package/dist/components/q2-dropdown-item2.js.map +1 -1
- package/dist/components/q2-file-picker.js +1 -1
- package/dist/components/q2-file-picker.js.map +1 -1
- package/dist/components/q2-option-list2.js +7 -5
- package/dist/components/q2-option-list2.js.map +1 -1
- package/dist/components/q2-option2.js +15 -1
- package/dist/components/q2-option2.js.map +1 -1
- package/dist/esm/q2-badge_7.entry.js +13 -5
- package/dist/esm/q2-badge_7.entry.js.map +1 -1
- package/dist/esm/q2-dropdown-item.entry.js +21 -2
- package/dist/esm/q2-dropdown-item.entry.js.map +1 -1
- package/dist/esm/q2-file-picker.entry.js +1 -1
- package/dist/esm/q2-file-picker.entry.js.map +1 -1
- package/dist/esm/q2-option-list_2.entry.js +7 -5
- package/dist/esm/q2-option-list_2.entry.js.map +1 -1
- package/dist/esm/q2-option.entry.js +15 -1
- package/dist/esm/q2-option.entry.js.map +1 -1
- package/dist/q2-tecton-elements/q2-badge_7.entry.js +8 -7
- package/dist/q2-tecton-elements/q2-badge_7.entry.js.map +1 -1
- package/dist/q2-tecton-elements/q2-dropdown-item.entry.js +23 -6
- package/dist/q2-tecton-elements/q2-dropdown-item.entry.js.map +1 -1
- package/dist/q2-tecton-elements/q2-file-picker.entry.js +1 -1
- package/dist/q2-tecton-elements/q2-file-picker.entry.js.map +1 -1
- package/dist/q2-tecton-elements/q2-option-list_2.entry.js +29 -23
- package/dist/q2-tecton-elements/q2-option-list_2.entry.js.map +1 -1
- package/dist/q2-tecton-elements/q2-option.entry.js +35 -15
- package/dist/q2-tecton-elements/q2-option.entry.js.map +1 -1
- package/dist/types/components/q2-dropdown-item/q2-dropdown-item.d.ts +8 -0
- package/dist/types/components/q2-option/q2-option.d.ts +7 -0
- package/dist/types/components.d.ts +11 -0
- package/dist/types/utils/mirror-emit.d.ts +11 -0
- package/package.json +3 -3
|
@@ -114,12 +114,20 @@ export class Q2Btn {
|
|
|
114
114
|
}
|
|
115
115
|
get buttonClasses() {
|
|
116
116
|
const classes = [];
|
|
117
|
-
if (this.iconPosition)
|
|
117
|
+
if (this.iconPosition)
|
|
118
118
|
classes.push(`icon-${this.iconPosition}`);
|
|
119
|
-
|
|
120
|
-
if (this.intent === 'coin') {
|
|
119
|
+
if (this.intent === 'coin')
|
|
121
120
|
classes.push('intent-coin');
|
|
122
|
-
|
|
121
|
+
if (!!this.block)
|
|
122
|
+
classes.push('is-block');
|
|
123
|
+
if (!!this.color)
|
|
124
|
+
classes.push('has-color');
|
|
125
|
+
if (!!this.intent)
|
|
126
|
+
classes.push(`has-intent`);
|
|
127
|
+
if (!!this.size)
|
|
128
|
+
classes.push('has-size');
|
|
129
|
+
if (!!this.active)
|
|
130
|
+
classes.push('is-active');
|
|
123
131
|
return classes.join(' ');
|
|
124
132
|
}
|
|
125
133
|
get coinLabelClasses() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"q2-btn.js","sourceRoot":"","sources":["../../../src/components/q2-btn/q2-btn.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,EAAsB,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAChH,OAAO,EACH,oBAAoB,EACpB,eAAe,EACf,WAAW,EACX,kBAAkB,EAClB,GAAG,EACH,aAAa,EACb,wBAAwB,GAC3B,MAAM,WAAW,CAAC;AAGnB,MAAM,OAAO,KAAK;;QA0Nd,qBAAgB,GAAG,GAAG,EAAE;YACpB,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;gBACzB,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;YACnD,CAAC;QACL,CAAC,CAAC;QAEF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E,GAAI,IAAI,CAAC,iBAAiB,CAAC,EAClE,QAAQ,EAAE,IAAI,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,IAE/C,IAAI,CAAC,YAAY,EAAE,CAClB,CACT,CAAC,CAAC,CAAC,CACA,IAAI,CAAC,YAAY,EAAE,CACtB,CAAC;IACN,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAGJ","sourcesContent":["import { Component, State, Prop, h, ComponentInterface, Watch, Listen, Element, Fragment } from '@stencil/core';\nimport {\n getAriaValueFromProp,\n handleAriaLabel,\n handleColor,\n isEventFromElement,\n loc,\n overrideFocus,\n handleDeprecationWarning,\n} from 'src/utils';\n\n@Component({ tag: 'q2-btn', shadow: true, styleUrl: 'q2-btn.scss' })\nexport class Q2Btn implements ComponentInterface {\n // #region Own Properties\n\n primaryBtn: HTMLButtonElement;\n primaryBtnWrapper: HTMLElement;\n\n // #endregion\n // #region Host HTML Element\n\n @Element()\n hostElement: HTMLElement;\n\n // #endregion\n // #region State Properties\n\n @State()\n iconPosition: 'left' | 'right' | 'only';\n\n // #endregion\n // #region Public Property API\n\n /**\n * @private\n * Role attribute for better semantic accessibility support\n */\n @Prop({ reflect: true })\n _role: string;\n\n /**\n * Displays the component in an active state.\n *\n * @info\n * Only intended for use with the `badge` property.\n * @deprecated\n */\n @Prop({ reflect: true })\n active: boolean;\n\n @Prop()\n ariaControls: string;\n\n @Prop()\n ariaExpanded: string;\n\n @Prop()\n ariaHasPopup: string;\n\n /** @deprecated */\n @Prop({ reflect: true, mutable: true })\n ariaLabel: string;\n\n @Prop()\n ariaPressed: string;\n\n @Prop()\n ariaSelected: string;\n\n /**\n * Displays the component in a smaller, badge style.\n * @deprecated\n */\n @Prop({ reflect: true })\n badge: boolean;\n\n /** The component expands to fill the width of its parent element. */\n @Prop({ reflect: true })\n block: boolean;\n\n /** @deprecated */\n @Prop({ reflect: true, mutable: true })\n color: string; // deprecated but need it to use utils/handleColor\n\n @Prop()\n description: string;\n\n /** Marks the component as disabled and displays a `not-allowed` cursor on hover. */\n @Prop({ reflect: true })\n disabled: boolean;\n\n /** @deprecated */\n @Prop({ reflect: true })\n fab: boolean;\n\n /**\n * Hides the `label`, and assigns its value to the `aria-label` attribute on the `<button>` element.\n */\n @Prop({ reflect: true, mutable: true })\n hideLabel: boolean;\n\n /**\n * Indicates the role of the component in the workflow, which will apply appropriate styling to the component.\n */\n @Prop({ reflect: true, mutable: true })\n intent:\n | 'coin'\n | 'neutral-text'\n | 'neutral'\n | 'workflow-destroy'\n | 'workflow-escape'\n | 'workflow-primary'\n | 'workflow-secondary';\n\n /**\n * Defines the text content of the button if it is not provided in the `<slot>` of the element.\n * Also used for the `aria-label` of the `<button>` element when only displaying an icon.\n *\n * @localizable\n */\n @Prop({ reflect: true, mutable: true })\n label: string;\n\n /** Displays the button with a loading spinner to indicate something is happening in the background and the user should not click again. */\n @Prop({ reflect: true })\n loading: boolean;\n\n /**\n * Defines the size of q2-btn, it renders as default size if not provided.\n */\n @Prop({ reflect: true })\n size: 'small' | 'medium' | 'large';\n\n @Prop()\n tabIndex: number;\n\n /** The default behavior of the button. */\n @Prop({ reflect: true })\n type: string = 'button';\n\n // #endregion\n // #region Component Lifecycle Events\n\n componentWillLoad() {\n this.handleIcons();\n handleAriaLabel(this);\n handleColor(this);\n }\n\n componentDidLoad(): void {\n this.handleButtonSize();\n overrideFocus(this.hostElement);\n }\n\n // #endregion\n // #region Listeners\n\n @Listen('click', { capture: true })\n handleClick(event: Event) {\n if (this.loading || this.disabled) {\n event.stopImmediatePropagation();\n }\n this.primaryBtn.focus();\n }\n\n @Listen('focus')\n delegateFocus(event: FocusEvent) {\n if (!isEventFromElement(event, this.hostElement)) return;\n this.primaryBtn.focus();\n }\n\n // #endregion\n // #region Watchers\n\n @Watch('ariaLabel')\n ariaLabelObserver() {\n handleAriaLabel(this);\n }\n\n @Watch('size')\n sizeObserver() {\n this.handleButtonSize();\n }\n\n // #endregion\n // #region Local Methods\n\n get buttonAttributes() {\n return {\n ariaExpanded: getAriaValueFromProp(this.ariaExpanded, ['true', 'false']),\n ariaHasPopup: getAriaValueFromProp(this.ariaHasPopup, [\n 'true',\n 'false',\n 'menu',\n 'listbox',\n 'tree',\n 'grid',\n 'dialog',\n ]),\n ariaLabel: this.label && this.hideLabel ? loc(this.label) : undefined,\n ariaSelected: getAriaValueFromProp(this.ariaSelected, ['true', 'false']),\n ariaPressed: getAriaValueFromProp(this.ariaPressed, ['true', 'false']),\n description: this.description !== undefined ? this.description : undefined,\n disabled: this.disabled || false,\n type: this.type,\n tabindex: this.tabIndex || undefined,\n };\n }\n\n get buttonClasses() {\n const classes = [];\n if (this.iconPosition) {\n classes.push(`icon-${this.iconPosition}`);\n }\n if (this.intent === 'coin') {\n classes.push('intent-coin');\n }\n\n return classes.join(' ');\n }\n\n get coinLabelClasses() {\n const classes = ['coin-label'];\n if (this.disabled) {\n classes.push('disabled');\n }\n\n return classes.join(' ');\n }\n\n handleButtonSize = () => {\n if (Number(this.size) <= 4) {\n handleDeprecationWarning(this, 'size', 'prop');\n }\n };\n\n handleIcons = () => {\n // Only allow one icon in the button\n const icon = Array.from(this.hostElement.querySelectorAll(':scope > q2-icon')).reduce((acc, element) => {\n if (acc) element.remove();\n else acc = element;\n return acc;\n }, null);\n\n const hasIcon = !!icon;\n const hasLoc = !!this.hostElement.querySelector('q2-loc');\n const hasText = !!this.hostElement.textContent.trim();\n const hasIconLeft = (hasLoc || hasText) && hasIcon && this.hostElement.firstElementChild === icon;\n const hasIconRight = (hasLoc || hasText) && hasIcon && this.hostElement.lastElementChild === icon;\n const hasIconOnly = !hasIconLeft && !hasIconRight && hasIcon;\n\n let iconPosition;\n if (hasIconOnly) iconPosition = 'only';\n else if (hasIconLeft) iconPosition = 'left';\n else if (hasIconRight) iconPosition = 'right';\n this.iconPosition = iconPosition;\n };\n\n handleSlotChange = () => {\n this.handleIcons();\n };\n\n // #endregion\n // #region Render Methods\n\n renderButton() {\n const { ariaExpanded, ariaHasPopup, ariaSelected, ariaPressed, description, disabled, type, tabindex } =\n this.buttonAttributes;\n const { iconPosition, loading, badge, label, hideLabel } = this;\n const renderLoadingSpinner = iconPosition || loading;\n const isLoadingSpinnerInline = !iconPosition || badge;\n return (\n <Fragment>\n <button\n ref={el => (this.primaryBtn = el ?? this.primaryBtn)}\n aria-expanded={ariaExpanded}\n aria-haspopup={ariaHasPopup}\n aria-label={hideLabel && loc(label)}\n aria-selected={ariaSelected}\n aria-pressed={ariaPressed}\n disabled={disabled}\n type={type}\n tabindex={tabindex}\n test-id=\"q2BtnInnerButton\"\n class={this.buttonClasses}\n aria-describedby={!!description ? 'hidden-description' : undefined}\n aria-labelledby={this.intent === 'coin' && !hideLabel ? 'coin-label' : undefined}\n role={this._role || undefined}\n >\n <div class=\"slot-container\">\n {renderLoadingSpinner && (\n <q2-loading\n hidden={!loading}\n modifiers={isLoadingSpinnerInline ? 'inline' : undefined}\n />\n )}\n {this.renderDefaultLabel()}\n {this.renderDefaultCoinSlot()}\n </div>\n </button>\n {this.renderCoinLabel()}\n {!!description && (\n <div\n id=\"hidden-description\"\n aria-hidden=\"true\"\n class=\"sr\"\n >\n {description}\n </div>\n )}\n </Fragment>\n );\n }\n\n renderCoinLabel() {\n if (this.intent !== 'coin' || this.hideLabel) return;\n return (\n <div\n id=\"coin-label\"\n class={this.coinLabelClasses}\n >\n {this.label ? (\n loc(this.label)\n ) : (\n <slot\n name=\"coin-label\"\n onSlotchange={this.handleSlotChange}\n />\n )}\n </div>\n );\n }\n\n renderDefaultCoinSlot() {\n if (this.intent !== 'coin') return;\n return <slot onSlotchange={this.handleSlotChange} />;\n }\n\n renderDefaultLabel() {\n if (this.intent === 'coin') return;\n if (!this.hideLabel && this.label) return loc(this.label);\n return <slot onSlotchange={this.handleSlotChange} />;\n }\n\n render() {\n return (this.size === 'small' && this.iconPosition !== 'only') || this.intent === 'coin' ? (\n // wrap only for small sized and coin intent\n <div\n class={this.size === 'small' ? 'btn-height-wrapper' : 'coin-wrapper'}\n ref={el => (this.primaryBtnWrapper = el ?? this.primaryBtnWrapper)}\n tabIndex={this.size === 'small' ? -1 : undefined}\n >\n {this.renderButton()}\n </div>\n ) : (\n this.renderButton()\n );\n }\n\n // #endregion\n}\n"]}
|
|
1
|
+
{"version":3,"file":"q2-btn.js","sourceRoot":"","sources":["../../../src/components/q2-btn/q2-btn.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,EAAsB,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAChH,OAAO,EACH,oBAAoB,EACpB,eAAe,EACf,WAAW,EACX,kBAAkB,EAClB,GAAG,EACH,aAAa,EACb,wBAAwB,GAC3B,MAAM,WAAW,CAAC;AAGnB,MAAM,OAAO,KAAK;;QA2Nd,qBAAgB,GAAG,GAAG,EAAE;YACpB,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;gBACzB,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;YACnD,CAAC;QACL,CAAC,CAAC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stencil/core';\nimport {\n getAriaValueFromProp,\n handleAriaLabel,\n handleColor,\n isEventFromElement,\n loc,\n overrideFocus,\n handleDeprecationWarning,\n} from 'src/utils';\n\n@Component({ tag: 'q2-btn', shadow: true, styleUrl: 'q2-btn.scss' })\nexport class Q2Btn implements ComponentInterface {\n // #region Own Properties\n\n primaryBtn: HTMLButtonElement;\n primaryBtnWrapper: HTMLElement;\n\n // #endregion\n // #region Host HTML Element\n\n @Element()\n hostElement: HTMLElement;\n\n // #endregion\n // #region State Properties\n\n @State()\n iconPosition: 'left' | 'right' | 'only';\n\n // #endregion\n // #region Public Property API\n\n /**\n * @private\n * Role attribute for better semantic accessibility support\n */\n @Prop({ reflect: true })\n _role: string;\n\n /**\n * Displays the component in an active state.\n *\n * @info\n * Only intended for use with the `badge` property.\n * @deprecated\n */\n @Prop({ reflect: true })\n active: boolean;\n\n @Prop()\n ariaControls: string;\n\n @Prop()\n ariaExpanded: string;\n\n @Prop()\n ariaHasPopup: string;\n\n /** @deprecated */\n @Prop({ reflect: true, mutable: true })\n ariaLabel: string;\n\n @Prop()\n ariaPressed: string;\n\n @Prop()\n ariaSelected: string;\n\n /**\n * Displays the component in a smaller, badge style.\n * @deprecated\n */\n @Prop({ reflect: true })\n badge: boolean;\n\n /** The component expands to fill the width of its parent element. */\n @Prop({ reflect: true })\n block: boolean;\n\n /** @deprecated */\n @Prop({ reflect: true, mutable: true })\n color: string; // deprecated but need it to use utils/handleColor\n\n @Prop()\n description: string;\n\n /** Marks the component as disabled and displays a `not-allowed` cursor on hover. */\n @Prop({ reflect: true })\n disabled: boolean;\n\n /** @deprecated */\n @Prop({ reflect: true })\n fab: boolean;\n\n /**\n * Hides the `label`, and assigns its value to the `aria-label` attribute on the `<button>` element.\n */\n @Prop({ reflect: true, mutable: true })\n hideLabel: boolean;\n\n /**\n * Indicates the role of the component in the workflow, which will apply appropriate styling to the component.\n */\n @Prop({ reflect: true, mutable: true })\n intent:\n | 'coin'\n | 'neutral-text'\n | 'neutral'\n | 'workflow-destroy'\n | 'workflow-escape'\n | 'workflow-primary'\n | 'workflow-secondary';\n\n /**\n * Defines the text content of the button if it is not provided in the `<slot>` of the element.\n * Also used for the `aria-label` of the `<button>` element when only displaying an icon.\n *\n * @localizable\n */\n @Prop({ reflect: true, mutable: true })\n label: string;\n\n /** Displays the button with a loading spinner to indicate something is happening in the background and the user should not click again. */\n @Prop({ reflect: true })\n loading: boolean;\n\n /**\n * Defines the size of q2-btn, it renders as default size if not provided.\n */\n @Prop({ reflect: true })\n size: 'small' | 'medium' | 'large';\n\n @Prop()\n tabIndex: number;\n\n /** The default behavior of the button. */\n @Prop({ reflect: true })\n type: string = 'button';\n\n // #endregion\n // #region Component Lifecycle Events\n\n componentWillLoad() {\n this.handleIcons();\n handleAriaLabel(this);\n handleColor(this);\n }\n\n componentDidLoad(): void {\n this.handleButtonSize();\n overrideFocus(this.hostElement);\n }\n\n // #endregion\n // #region Listeners\n\n @Listen('click', { capture: true })\n handleClick(event: Event) {\n if (this.loading || this.disabled) {\n event.stopImmediatePropagation();\n }\n this.primaryBtn.focus();\n }\n\n @Listen('focus')\n delegateFocus(event: FocusEvent) {\n if (!isEventFromElement(event, this.hostElement)) return;\n this.primaryBtn.focus();\n }\n\n // #endregion\n // #region Watchers\n\n @Watch('ariaLabel')\n ariaLabelObserver() {\n handleAriaLabel(this);\n }\n\n @Watch('size')\n sizeObserver() {\n this.handleButtonSize();\n }\n\n // #endregion\n // #region Local Methods\n\n get buttonAttributes() {\n return {\n ariaExpanded: getAriaValueFromProp(this.ariaExpanded, ['true', 'false']),\n ariaHasPopup: getAriaValueFromProp(this.ariaHasPopup, [\n 'true',\n 'false',\n 'menu',\n 'listbox',\n 'tree',\n 'grid',\n 'dialog',\n ]),\n ariaLabel: this.label && this.hideLabel ? loc(this.label) : undefined,\n ariaSelected: getAriaValueFromProp(this.ariaSelected, ['true', 'false']),\n ariaPressed: getAriaValueFromProp(this.ariaPressed, ['true', 'false']),\n description: this.description !== undefined ? this.description : undefined,\n disabled: this.disabled || false,\n type: this.type,\n tabindex: this.tabIndex || undefined,\n };\n }\n\n get buttonClasses() {\n const classes = [];\n if (this.iconPosition) classes.push(`icon-${this.iconPosition}`);\n if (this.intent === 'coin') classes.push('intent-coin');\n if (!!this.block) classes.push('is-block');\n if (!!this.color) classes.push('has-color');\n if (!!this.intent) classes.push(`has-intent`);\n if (!!this.size) classes.push('has-size');\n if (!!this.active) classes.push('is-active');\n\n return classes.join(' ');\n }\n\n get coinLabelClasses() {\n const classes = ['coin-label'];\n if (this.disabled) {\n classes.push('disabled');\n }\n\n return classes.join(' ');\n }\n\n handleButtonSize = () => {\n if (Number(this.size) <= 4) {\n handleDeprecationWarning(this, 'size', 'prop');\n }\n };\n\n handleIcons = () => {\n // Only allow one icon in the button\n const icon = Array.from(this.hostElement.querySelectorAll(':scope > q2-icon')).reduce((acc, element) => {\n if (acc) element.remove();\n else acc = element;\n return acc;\n }, null);\n\n const hasIcon = !!icon;\n const hasLoc = !!this.hostElement.querySelector('q2-loc');\n const hasText = !!this.hostElement.textContent.trim();\n const hasIconLeft = (hasLoc || hasText) && hasIcon && this.hostElement.firstElementChild === icon;\n const hasIconRight = (hasLoc || hasText) && hasIcon && this.hostElement.lastElementChild === icon;\n const hasIconOnly = !hasIconLeft && !hasIconRight && hasIcon;\n\n let iconPosition;\n if (hasIconOnly) iconPosition = 'only';\n else if (hasIconLeft) iconPosition = 'left';\n else if (hasIconRight) iconPosition = 'right';\n this.iconPosition = iconPosition;\n };\n\n handleSlotChange = () => {\n this.handleIcons();\n };\n\n // #endregion\n // #region Render Methods\n\n renderButton() {\n const { ariaExpanded, ariaHasPopup, ariaSelected, ariaPressed, description, disabled, type, tabindex } =\n this.buttonAttributes;\n const { iconPosition, loading, badge, label, hideLabel } = this;\n const renderLoadingSpinner = iconPosition || loading;\n const isLoadingSpinnerInline = !iconPosition || badge;\n return (\n <Fragment>\n <button\n ref={el => (this.primaryBtn = el ?? this.primaryBtn)}\n aria-expanded={ariaExpanded}\n aria-haspopup={ariaHasPopup}\n aria-label={hideLabel && loc(label)}\n aria-selected={ariaSelected}\n aria-pressed={ariaPressed}\n disabled={disabled}\n type={type}\n tabindex={tabindex}\n test-id=\"q2BtnInnerButton\"\n class={this.buttonClasses}\n aria-describedby={!!description ? 'hidden-description' : undefined}\n aria-labelledby={this.intent === 'coin' && !hideLabel ? 'coin-label' : undefined}\n role={this._role || undefined}\n >\n <div class=\"slot-container\">\n {renderLoadingSpinner && (\n <q2-loading\n hidden={!loading}\n modifiers={isLoadingSpinnerInline ? 'inline' : undefined}\n />\n )}\n {this.renderDefaultLabel()}\n {this.renderDefaultCoinSlot()}\n </div>\n </button>\n {this.renderCoinLabel()}\n {!!description && (\n <div\n id=\"hidden-description\"\n aria-hidden=\"true\"\n class=\"sr\"\n >\n {description}\n </div>\n )}\n </Fragment>\n );\n }\n\n renderCoinLabel() {\n if (this.intent !== 'coin' || this.hideLabel) return;\n return (\n <div\n id=\"coin-label\"\n class={this.coinLabelClasses}\n >\n {this.label ? (\n loc(this.label)\n ) : (\n <slot\n name=\"coin-label\"\n onSlotchange={this.handleSlotChange}\n />\n )}\n </div>\n );\n }\n\n renderDefaultCoinSlot() {\n if (this.intent !== 'coin') return;\n return <slot onSlotchange={this.handleSlotChange} />;\n }\n\n renderDefaultLabel() {\n if (this.intent === 'coin') return;\n if (!this.hideLabel && this.label) return loc(this.label);\n return <slot onSlotchange={this.handleSlotChange} />;\n }\n\n render() {\n return (this.size === 'small' && this.iconPosition !== 'only') || this.intent === 'coin' ? (\n // wrap only for small sized and coin intent\n <div\n class={this.size === 'small' ? 'btn-height-wrapper' : 'coin-wrapper'}\n ref={el => (this.primaryBtnWrapper = el ?? this.primaryBtnWrapper)}\n tabIndex={this.size === 'small' ? -1 : undefined}\n >\n {this.renderButton()}\n </div>\n ) : (\n this.renderButton()\n );\n }\n\n // #endregion\n}\n"]}
|
|
@@ -15,6 +15,8 @@ describe('q2-dropdown', () => {
|
|
|
15
15
|
let lastOption;
|
|
16
16
|
let lastOptionFocusSpy;
|
|
17
17
|
let closeDropdownBtn;
|
|
18
|
+
let clickSpy;
|
|
19
|
+
let tctClickSpy;
|
|
18
20
|
it('properly compiles CSS vars and functions', async () => {
|
|
19
21
|
const page = await setup({ html: '<q2-dropdown></q2-dropdown>' });
|
|
20
22
|
expect(await getListOfStyleCompilationIssues(page, 'q2-dropdown')).toHaveLength(0);
|
|
@@ -823,8 +825,8 @@ describe('q2-dropdown', () => {
|
|
|
823
825
|
page = await setup({
|
|
824
826
|
html: `
|
|
825
827
|
<q2-dropdown>
|
|
826
|
-
<q2-dropdown-item test-id="option-1">Item 1 Text</q2-dropdown-item>
|
|
827
|
-
<q2-dropdown-item test-id="option-2">Item 2 Text</q2-dropdown-item>
|
|
828
|
+
<q2-dropdown-item test-id="option-1" value="1">Item 1 Text</q2-dropdown-item>
|
|
829
|
+
<q2-dropdown-item test-id="option-2" value="2">Item 2 Text</q2-dropdown-item>
|
|
828
830
|
</q2-dropdown>
|
|
829
831
|
<button test-id="outer-button">Outside Button</button>
|
|
830
832
|
`,
|
|
@@ -838,6 +840,8 @@ describe('q2-dropdown', () => {
|
|
|
838
840
|
lastOptionFocusSpy = await lastOption.spyOnEvent('focus');
|
|
839
841
|
dropdownContainer = await page.find('q2-dropdown >>> click-elsewhere');
|
|
840
842
|
popover = await page.find('q2-dropdown >>> q2-popover');
|
|
843
|
+
clickSpy = await firstOption.spyOnEvent('click');
|
|
844
|
+
tctClickSpy = await firstOption.spyOnEvent('tctClick');
|
|
841
845
|
expect(await dropdown.getProperty('open')).toBeUndefined();
|
|
842
846
|
expect(buttonFocusSpy).toHaveReceivedEventTimes(0);
|
|
843
847
|
expect(popover).not.toHaveAttribute('open');
|
|
@@ -950,6 +954,38 @@ describe('q2-dropdown', () => {
|
|
|
950
954
|
await page.waitForChanges();
|
|
951
955
|
expect(lastOptionFocusSpy).toHaveReceivedEventTimes(1);
|
|
952
956
|
});
|
|
957
|
+
it('Space: selects the focused option', async () => {
|
|
958
|
+
await dropdownButton.press('ArrowDown');
|
|
959
|
+
await page.waitForChanges();
|
|
960
|
+
expect(popover).toHaveAttribute('open');
|
|
961
|
+
expect(firstOptionFocusSpy).toHaveReceivedEventTimes(1);
|
|
962
|
+
await page.keyboard.press('Space');
|
|
963
|
+
await page.waitForChanges();
|
|
964
|
+
const eventDetail = {
|
|
965
|
+
type: 'select',
|
|
966
|
+
value: '1',
|
|
967
|
+
};
|
|
968
|
+
expect(clickSpy).toHaveReceivedEventDetail(eventDetail);
|
|
969
|
+
expect(tctClickSpy).toHaveReceivedEventDetail(eventDetail);
|
|
970
|
+
expect(popover).not.toHaveAttribute('open');
|
|
971
|
+
expect(await getFocusedAttribute(page, 'test-id')).toEqual('dropdownButton');
|
|
972
|
+
});
|
|
973
|
+
it('Enter: selects the focused option', async () => {
|
|
974
|
+
await dropdownButton.press('ArrowDown');
|
|
975
|
+
await page.waitForChanges();
|
|
976
|
+
expect(popover).toHaveAttribute('open');
|
|
977
|
+
expect(firstOptionFocusSpy).toHaveReceivedEventTimes(1);
|
|
978
|
+
await page.keyboard.press('Enter');
|
|
979
|
+
await page.waitForChanges();
|
|
980
|
+
const eventDetail = {
|
|
981
|
+
type: 'select',
|
|
982
|
+
value: '1',
|
|
983
|
+
};
|
|
984
|
+
expect(clickSpy).toHaveReceivedEventDetail(eventDetail);
|
|
985
|
+
expect(tctClickSpy).toHaveReceivedEventDetail(eventDetail);
|
|
986
|
+
expect(popover).not.toHaveAttribute('open');
|
|
987
|
+
expect(await getFocusedAttribute(page, 'test-id')).toEqual('dropdownButton');
|
|
988
|
+
});
|
|
953
989
|
});
|
|
954
990
|
});
|
|
955
991
|
});
|