vault/ui/app/components/auth/fields.ts
claire bontempo c4cfa371c1
UI: Build Auth::FormTemplate (#30257)
* move auth tests to folder

* polish auth tests

* build auth::form-template component

* add components for other supported methods

* add comments, add tests

* convert to typesript

* conver base.js to typescript

* use getRelativePath helper

* fix logic for hiding advanced settings toggle, use getter for selecting tab index

* update tests

* how in the heck did that happen

* add punctuation to comments, clarify var name

* update loginFields to array of objects

* update tests

* add helper text and custom label tests

* woops, test was in the beforeEach block
2025-04-17 08:36:00 -07:00

35 lines
888 B
TypeScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
// TODO pending feedback from the security team, we may keep autocomplete="off" for login fields
import Component from '@glimmer/component';
interface Args {
loginFields: Field[];
}
interface Field {
name: string; // sets input name
label?: string; // label will be "name" capitalized unless label exists
helperText?: string;
}
export default class AuthFields extends Component<Args> {
// token or password should render as "password" types, otherwise render text inputs
setInputType = (field: string) => (['token', 'password'].includes(field) ? 'password' : 'text');
setAutocomplete = (fieldName: string) => {
switch (fieldName) {
case 'password':
return 'current-password';
case 'token':
return 'off';
default:
return fieldName;
}
};
}