Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 2894x 1x 1x 39x 2x 2x 2x 2x 39x 1x 1x 1x 276x 276x 276x 276x 276x 276x 1x 1x 1x 1x 1x 1x 1x 1x 1x 160x 160x 8x 8x 160x 160x 1x 1x 1x 139x 8x 8x 8x 139x 139x 139x 1x 1x 1x 541x 541x 541x 1x 1x 1x 305x 305x 305x 305x 1x 1x 1x 38551x 13793x 13793x 13793x 13793x 38551x 1x 1x 1x 5x 5x 1x 1x 1x 846x 846x 846x 846x 846x 846x 846x 846x 1x | /*******************************************************************************
* Copyright bei
* Entwicklungs- und Pflegeverbund für das gemeinsame Fachverfahren gefa
*
*******************************************************************************/
import {
Component,
ElementRef,
TemplateRef,
computed,
contentChild,
input,
output,
viewChild,
} from '@angular/core';
import { ActionEvent, HasFocusEvent } from '../utils/event.types';
import { isNotEmpty, isUndefOrEmpty } from '../utils/internal-utils';
import { FocusableElementOwner, Item } from '../utils/util.types';
import { TooltipComponent } from '../internal/tooltip/tooltip.component';
export type ButtonContentDisplay =
| 'icon-only'
| 'icon-only-circle'
| 'icon-left'
| 'icon-right'
| 'text-only'
| 'status';
const ARMED_EMULATION = 'gc-input-active';
/**
* A Button element that allows users to fire an action on a button press.
*/
@Component({
selector: 'gc-button',
templateUrl: './button.component.html',
styleUrls: ['./button.component.css'],
host: {
// host element generates an extra text node, which causes Firefox + Jaws to read out the button
// text twice when it's used in a list -> remove it from the a11y tree
role: 'none',
},
standalone: false,
})
export class ButtonComponent<MenuItem extends Item = Item>
implements FocusableElementOwner
{
/*@ignore*/
public get hasFocus(): boolean {
return this.button().nativeElement === document.activeElement;
}
/**
* The label that shows on the button.
*/
public readonly label = input<string>('');
/**
* The visual type of the button.
*/
public readonly variant = input<'primary' | 'secondary' | 'tertiary'>(
'primary',
);
/**
* Define how the content is displayed
* - icon-only: only the icon is shown
* - icon-only-circle: only the icon is shown in a circular shape
* - icon-left: icon is shown on the left of the text
* - icon-right: icon is shown on the right of the text
* - text-only: only text is displayed
* - status: only the icon is shown but using the width of the label
*/
public readonly contentDisplay = input<ButtonContentDisplay>('text-only');
/**
* Text displayed as a tooltip to the user
*/
public readonly tooltipText = input<string>();
/**
* @ignore
*/
public readonly _supportLiveTextChange = input<boolean>(false);
/**
* Automatically focus the control if it is contained in an area tagged with data-gc-auto-focus-area
*/
public readonly autoFocus = input<boolean>(false);
/**
* If not empty, the button will open a menu on click and render these as items of the menu.
*/
public readonly menuItems = input<readonly MenuItem[]>([]);
/**
* Decides on which side of the menu button the menu is going to appear.
*/
public readonly menuAlignment = input<'start' | 'end' | 'auto'>('end');
/** Optional icon provider to use for menu-items */
public readonly menuItemIconProvider =
input<TemplateRef<{ $implicit: MenuItem }>>();
/**
* Menu items that should be disabled in the menu.
*/
public readonly disabledMenuItems = input<ReadonlySet<string>>(new Set());
/**
* @ignore
* Overrides the default tabindex value.
*/
public readonly _tabIndexOverride = input<number>();
/**
* @ignore
* Overrides the aria-controls of the native button
*/
public readonly _ariaControlsOverride = input<string>();
/**
* @ignore
* Overrides the aria-controls of the native button
*/
public readonly _ariaExpandedOverride = input<boolean>();
/**
* Event which is fired when an menu item is activated.
*/
public readonly onMenuAction = output<MenuItem>();
/**
* The method that gets fired when the button is pressed.
*/
public readonly onAction = output<ActionEvent>();
/**
* @ignore
*/
public readonly _onHasFocus = output<HasFocusEvent>();
/**
* If set to true the button state is set to disabled which means that it is no longer clickable.
*/
public readonly disabled = input(false);
/**
* @ignore
*/
protected readonly textForTooltip = computed(() => {
const tooltipText = this.tooltipText();
if (tooltipText != null) {
return tooltipText;
}
return this._hasGraphicTooltip() ? this.label() : '';
});
/** @ignore */
protected areAllMenuItemsDisabled = computed(() => {
return (
this.menuItems().length > 0 &&
this.menuItems().every(item => this.disabledMenuItems().has(item.key))
);
});
/** @ignore */
private readonly button =
viewChild.required<ElementRef<HTMLElement>>('button');
/** @ignore */
private readonly tooltip = contentChild(TooltipComponent);
focusChild(): boolean {
if (!this.disabled()) {
this.button().nativeElement.focus();
return true;
}
return false;
}
/** @ignore */
_handleOnClick(event: MouseEvent): void {
this.onAction.emit({
ctrlKey: event.ctrlKey,
metaKey: event.metaKey,
shiftKey: event.shiftKey,
});
}
/**
* @ignore
* @deprecated use moveFocus
*/
_focus(): void {
this.button().nativeElement.focus();
}
/** @ignore */
_onKeyDown(event: KeyboardEvent): void {
// We need to emulate the armed state for FF
if (event.key == ' ') {
// only emulate for space - ENTER executes the action on key-down already and so native buttons also do not show that
(event.currentTarget as HTMLButtonElement).classList.add(ARMED_EMULATION);
}
}
/** @ignore */
_onKeyUp(event: KeyboardEvent): void {
if (event.key == ' ') {
// only emulate for space - ENTER executes the action on key-down already and so native buttons also do not show that
(event.currentTarget as HTMLButtonElement).classList.remove(
ARMED_EMULATION,
);
}
}
/** @ignore */
_onFocus(): void {
this.refreshAriaLive();
this._onHasFocus.emit({ hasFocus: true });
}
/** @ignore */
_onBlur(): void {
this.refreshAriaLive();
this.button().nativeElement.classList.remove(ARMED_EMULATION); // Safe guard to clean up if the key-up is not received
this._onHasFocus.emit({ hasFocus: false });
}
/** @ignore */
_hasGraphicTooltip(): boolean {
if (!this.contentDisplay().includes('icon-only')) {
return false;
}
return isUndefOrEmpty(this.tooltipText()) && isNotEmpty(this.label());
}
/** @ignore */
_hideTooltip(): void {
this.tooltip()?.hide();
}
/** @ignore */
private refreshAriaLive() {
// directly interface with the element befor the other DOM-Syncs happen
const el = this.button().nativeElement;
if (this._supportLiveTextChange() && !this.disabled() && this.hasFocus) {
el.setAttribute('aria-live', 'polite');
} else {
el.removeAttribute('aria-live');
}
}
}
|