UNPKG

uicore-ts

Version:

UICore is a library to build native-like user interfaces using pure Typescript. No HTML is needed at all. Components are described as TS classes and all user interactions are handled explicitly. This library is strongly inspired by the UIKit framework tha

136 lines (135 loc) 6.01 kB
import { UIColor } from "./UIColor"; import { ValueOf } from "./UIObject"; import { UITextView } from "./UITextView"; import { UIView, UIViewAddControlEventTargetObject, UIViewBroadcastEvent } from "./UIView"; export declare class UITextField extends UITextView { _placeholderTextKey?: string; _defaultPlaceholderText?: string; _viewHTMLElement: HTMLInputElement; _datalistElement?: HTMLDataListElement; _nativeAutocompleteData: string[]; _hasCommittedSelection: boolean; /** Minimum characters required before showing autocomplete suggestions */ minCharactersForAutocomplete: number; /** * When YES, hides the datalist if the current text exactly matches * a single autocomplete option (avoids showing redundant single suggestion). * Default is YES for better UX. */ hideNativeAutocompleteOnExactMatch: boolean; _validatesAgainstNativeAutocomplete: boolean; _isValidAgainstNativeAutocomplete: boolean; _validationInvalidBackgroundColor: UIColor; _validationInvalidBorderColor: UIColor; static controlEvent: { readonly PointerDown: "PointerDown"; readonly PointerMove: "PointerMove"; readonly PointerDrag: "PointerDrag"; readonly PointerLeave: "PointerLeave"; readonly PointerEnter: "PointerEnter"; readonly PointerUpInside: "PointerUpInside"; readonly PointerTap: "PointerTap"; readonly PointerUp: "PointerUp"; readonly MultipleTouches: "PointerZoom"; readonly PointerCancel: "PointerCancel"; readonly PointerHover: "PointerHover"; readonly EnterDown: "EnterDown"; readonly EnterUp: "EnterUp"; readonly SpaceDown: "SpaceDown"; readonly EscDown: "EscDown"; readonly TabDown: "TabDown"; readonly LeftArrowDown: "LeftArrowDown"; readonly RightArrowDown: "RightArrowDown"; readonly DownArrowDown: "DownArrowDown"; readonly UpArrowDown: "UpArrowDown"; readonly Focus: "Focus"; readonly Blur: "Blur"; } & { TextChange: string; ValidationChange: string; }; constructor(elementID?: string, viewHTMLElement?: null, type?: string | ValueOf<typeof UITextView.type>); get controlEventTargetAccumulator(): UIViewAddControlEventTargetObject<typeof UITextField>; get viewHTMLElement(): HTMLInputElement; set text(text: string); get text(): string; set placeholderText(text: string); get placeholderText(): string; setPlaceholderText(key: string, defaultString: string): void; /** * Controls whether the browser is allowed to autofill this field. * Defaults to YES. Set to NO for sensitive fields such as passwords * in registration or reset flows where autofill is undesirable. */ get autocompleteEnabled(): boolean; set autocompleteEnabled(enabled: boolean); didReceiveBroadcastEvent(event: UIViewBroadcastEvent): void; willMoveToSuperview(superview: UIView): void; _setPlaceholderFromKeyIfPossible(): void; get isSecure(): boolean; set isSecure(secure: boolean); /** * Sets the data for native browser autocomplete using HTML datalist. * Setting an empty array will remove the autocomplete functionality. * * @param data Array of strings to show as autocomplete suggestions */ set nativeAutocompleteData(data: string[]); get nativeAutocompleteData(): string[]; /** * When enabled, the text field will validate its content against the autocomplete list. * Invalid values will trigger a ValidationChange event and can be checked via isValidAgainstAutocomplete. * * Empty text is always considered valid (use required field validation separately if needed). */ set validatesAgainstNativeAutocomplete(validate: boolean); get validatesAgainstNativeAutocomplete(): boolean; /** * Returns YES if the current text value is valid according to autocomplete validation. * Always returns YES if validatesAgainstAutocomplete is disabled. * Empty text is considered valid. */ get isValidAgainstNativeAutocomplete(): boolean; /** * Background color to apply when validation fails. * Set to nil to disable background color change on invalid state. */ set validationInvalidBackgroundColor(color: UIColor); get validationInvalidBackgroundColor(): UIColor; /** * Border color to apply when validation fails. * Set to nil to disable border color change on invalid state. */ set validationInvalidBorderColor(color: UIColor); get validationInvalidBorderColor(): UIColor; /** * Validates the current text against the autocomplete list if validation is enabled. * Updates the _isValidAgainstAutocomplete flag and fires ValidationChange event on state change. */ _validateAgainstNativeAutocompleteIfNeeded(): void; _setValidationState(isValid: boolean): void; /** * Updates the visual state of the text field based on validation status. * Override this method to customize validation styling. */ _updateValidationVisualState(): void; /** * Clears the text field if the current value is not in the autocomplete list. * Useful for enforcing selection from the list only. * @returns YES if the text was cleared (was invalid), NO otherwise */ clearIfInvalid(): boolean; /** * Returns a list of autocomplete options that match the current text (case-insensitive). * Useful for implementing custom filtering or showing filtered results elsewhere. */ getMatchingAutocompleteOptions(): string[]; _updateDatalist(): void; _updateDatalistVisibility(): void; /** * Returns autocomplete options that match the given search text. * Uses case-insensitive substring matching (consistent with browser behavior). */ _getFilteredAutocompleteOptions(searchText: string): string[]; wasRemovedFromViewTree(): void; }