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

[chore]: create base class for text input and remove style and layout specific api #32080

Merged
merged 2 commits into from
Jul 24, 2024
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "chore: create base class for textinput and remove style and layout specific api",
"packageName": "@fluentui/web-components",
"email": "jes@microsoft.com",
"dependentChangeType": "patch"
}
132 changes: 68 additions & 64 deletions packages/web-components/docs/api-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,73 @@ export class BaseSpinner extends FASTElement {
elementInternals: ElementInternals;
}

// @public
export class BaseTextInput extends FASTElement {
autocomplete?: string;
autofocus: boolean;
// @internal
beforeinputHandler(e: InputEvent): boolean | void;
// @internal
changeHandler(e: InputEvent): boolean | void;
checkValidity(): boolean;
clickHandler(e: MouseEvent): boolean | void;
// (undocumented)
connectedCallback(): void;
// @internal
control: HTMLInputElement;
// @internal
controlLabel: HTMLLabelElement;
// @internal
defaultSlottedNodes: Node[];
// @internal
defaultSlottedNodesChanged(prev: Node[] | undefined, next: Node[] | undefined): void;
dirname?: string;
disabled?: boolean;
// @internal
elementInternals: ElementInternals;
focusinHandler(e: FocusEvent): boolean | void;
get form(): HTMLFormElement | null;
static readonly formAssociated = true;
formAttribute?: string;
// @internal
formResetCallback(): void;
initialValue: string;
// @internal
initialValueChanged(): void;
// @internal
inputHandler(e: InputEvent): boolean | void;
// @internal
keydownHandler(e: KeyboardEvent): boolean | void;
list: string;
maxlength: number;
minlength: number;
multiple: boolean;
name: string;
pattern: string;
placeholder: string;
readOnly?: boolean;
// @internal
readOnlyChanged(): void;
reportValidity(): boolean;
required: boolean;
// @internal
requiredChanged(previous: boolean, next: boolean): void;
select(): void;
setCustomValidity(message: string): void;
// @internal
setFormValue(value: File | string | FormData | null, state?: File | string | FormData | null): void;
// @internal
setValidity(flags?: Partial<ValidityState>, message?: string, anchor?: HTMLElement): void;
size: number;
spellcheck: boolean;
type: TextInputType;
get validationMessage(): string;
get validity(): ValidityState;
get value(): string;
set value(value: string);
get willValidate(): boolean;
}

// @public
export const borderRadiusCircular = "var(--borderRadiusCircular)";

Expand Down Expand Up @@ -3378,74 +3445,11 @@ export type TextFont = ValuesOf<typeof TextFont>;
// Warning: (ae-internal-mixed-release-tag) Mixed release tags are not allowed for "TextInput" because one of its declarations is marked as @internal
//
// @public
export class TextInput extends FASTElement {
export class TextInput extends BaseTextInput {
appearance?: TextInputAppearance;
appearanceChanged(prev: TextInputAppearance | undefined, next: TextInputAppearance | undefined): void;
autocomplete?: string;
autofocus: boolean;
// @internal
beforeinputHandler(e: InputEvent): boolean | void;
// @internal
changeHandler(e: InputEvent): boolean | void;
checkValidity(): boolean;
clickHandler(e: MouseEvent): boolean | void;
// (undocumented)
connectedCallback(): void;
// @internal
control: HTMLInputElement;
// @internal
controlLabel: HTMLLabelElement;
controlSize?: TextInputControlSize;
controlSizeChanged(prev: TextInputControlSize | undefined, next: TextInputControlSize | undefined): void;
// @internal
defaultSlottedNodes: Node[];
// @internal
defaultSlottedNodesChanged(prev: Node[] | undefined, next: Node[] | undefined): void;
dirname?: string;
disabled?: boolean;
// @internal
elementInternals: ElementInternals;
focusinHandler(e: FocusEvent): boolean | void;
get form(): HTMLFormElement | null;
static readonly formAssociated = true;
formAttribute?: string;
// @internal
formResetCallback(): void;
initialValue: string;
// @internal
initialValueChanged(): void;
// @internal
inputHandler(e: InputEvent): boolean | void;
// @internal
keydownHandler(e: KeyboardEvent): boolean | void;
list: string;
maxlength: number;
minlength: number;
multiple: boolean;
name: string;
pattern: string;
placeholder: string;
readOnly?: boolean;
// @internal
readOnlyChanged(): void;
reportValidity(): boolean;
required: boolean;
// @internal
requiredChanged(previous: boolean, next: boolean): void;
select(): void;
setCustomValidity(message: string): void;
// @internal
setFormValue(value: File | string | FormData | null, state?: File | string | FormData | null): void;
// @internal
setValidity(flags?: Partial<ValidityState>, message?: string, anchor?: HTMLElement): void;
size: number;
spellcheck: boolean;
type: TextInputType;
get validationMessage(): string;
get validity(): ValidityState;
get value(): string;
set value(value: string);
get willValidate(): boolean;
}

// @internal (undocumented)
Expand Down
1 change: 1 addition & 0 deletions packages/web-components/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ export {
} from './tabs/index.js';
export type { TabsOptions } from './tabs/index.js';
export {
BaseTextInput,
TextInput,
TextInputAppearance,
TextInputControlSize,
Expand Down
2 changes: 1 addition & 1 deletion packages/web-components/src/text-input/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export { definition as TextInputDefinition } from './text-input.definition.js';
export { TextInput } from './text-input.js';
export { BaseTextInput, TextInput } from './text-input.js';
export { TextInputAppearance, TextInputControlSize, TextInputType } from './text-input.options.js';
export type { TextInputOptions } from './text-input.options.js';
export { styles as TextInputStyles } from './text-input.styles.js';
Expand Down
106 changes: 57 additions & 49 deletions packages/web-components/src/text-input/text-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,7 @@ import { ImplicitSubmissionBlockingTypes, TextInputAppearance, TextInputType } f
* @csspart control - The internal `<input>` control
* @public
*/
export class TextInput extends FASTElement {
/**
* Indicates the styled appearance of the element.
*
* @public
* @remarks
* HTML Attribute: `appearance`
*/
@attr
public appearance?: TextInputAppearance;

/**
* Handles changes to appearance attribute custom states
* @param prev - the previous state
* @param next - the next state
*/
public appearanceChanged(prev: TextInputAppearance | undefined, next: TextInputAppearance | undefined) {
if (prev) {
toggleState(this.elementInternals, `${prev}`, false);
}
if (next) {
toggleState(this.elementInternals, `${next}`, true);
}
}

export class BaseTextInput extends FASTElement {
/**
* Indicates the element's autocomplete state.
* @see The {@link https://developer.mozilla.org/docs/Web/HTML/Attributes/autocomplete | `autocomplete`} attribute
Expand All @@ -64,30 +40,6 @@ export class TextInput extends FASTElement {
@attr({ mode: 'boolean' })
public autofocus!: boolean;

/**
* Sets the size of the control.
*
* @public
* @remarks
* HTML Attribute: `control-size`
*/
@attr({ attribute: 'control-size' })
public controlSize?: TextInputControlSize;

/**
* Handles changes to `control-size` attribute custom states
* @param prev - the previous state
* @param next - the next state
*/
public controlSizeChanged(prev: TextInputControlSize | undefined, next: TextInputControlSize | undefined) {
if (prev) {
toggleState(this.elementInternals, `${prev}`, false);
}
if (next) {
toggleState(this.elementInternals, `${next}`, true);
}
}

/**
* The default slotted content. This is the content that appears in the text field label.
*
Expand Down Expand Up @@ -643,6 +595,62 @@ export class TextInput extends FASTElement {
}
}

/**
* A Text Input Custom HTML Element.
* Based on BaseTextInput and includes style and layout specific attributes
*
* @public
*/
export class TextInput extends BaseTextInput {
/**
* Indicates the styled appearance of the element.
*
* @public
* @remarks
* HTML Attribute: `appearance`
*/
@attr
public appearance?: TextInputAppearance;

/**
* Handles changes to appearance attribute custom states
* @param prev - the previous state
* @param next - the next state
*/
public appearanceChanged(prev: TextInputAppearance | undefined, next: TextInputAppearance | undefined) {
if (prev) {
toggleState(this.elementInternals, `${prev}`, false);
}
if (next) {
toggleState(this.elementInternals, `${next}`, true);
}
}

/**
* Sets the size of the control.
*
* @public
* @remarks
* HTML Attribute: `control-size`
*/
@attr({ attribute: 'control-size' })
public controlSize?: TextInputControlSize;

/**
* Handles changes to `control-size` attribute custom states
* @param prev - the previous state
* @param next - the next state
*/
public controlSizeChanged(prev: TextInputControlSize | undefined, next: TextInputControlSize | undefined) {
if (prev) {
toggleState(this.elementInternals, `${prev}`, false);
}
if (next) {
toggleState(this.elementInternals, `${next}`, true);
}
}
}

/**
* @internal
* @privateRemarks
Expand Down
Loading