Skip to content

Commit

Permalink
* pick: add readonly property to pick.
Browse files Browse the repository at this point in the history
  • Loading branch information
catouse committed Nov 24, 2023
1 parent 3bcb5d9 commit 3263365
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 5 deletions.
8 changes: 4 additions & 4 deletions lib/pick/src/components/pick-trigger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@ export class PickTrigger<S extends PickState = PickState, P extends PickTriggerP
}

protected _getClass(props: RenderableProps<P>) {
const {state, className, disabled} = props;
const {state, className, disabled, readonly} = props;
const {open: opened} = state;
return classes(
'pick',
className,
opened && 'is-open focus',
disabled && 'disabled',
readonly && 'readonly',
);
}

Expand All @@ -70,13 +71,12 @@ export class PickTrigger<S extends PickState = PickState, P extends PickTriggerP
}

protected _renderValue(props: RenderableProps<P>): ComponentChildren {
const {name, state: {value = ''}, disabled, id} = props;
const {name, state: {value = ''}, disabled, readonly, id} = props;
if (name) {
if (this._hasInput) {
$(`#${id}`).val(value);
} else {
return <input id={id} type="hidden" className="pick-value" name={name} value={value} disabled={disabled} />;

return <input id={id} type="hidden" className="pick-value" name={name} value={value} readonly={readonly} disabled={disabled} />;
}
}
return null;
Expand Down
4 changes: 3 additions & 1 deletion lib/pick/src/components/pick.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class Pick<S extends PickState = PickState, O extends PickOptions<S> = Pi
}

toggle = async (open?: boolean, state?: Partial<S>): Promise<S> => {
if (this.props.disabled) {
if (this.props.disabled || this.props.readonly) {
open = false;
}
const {state: currentState} = this;
Expand Down Expand Up @@ -125,6 +125,7 @@ export class Pick<S extends PickState = PickState, O extends PickOptions<S> = Pi
tagName: props.tagName,
attrs: props.attrs,
disabled: props.disabled,
readonly: props.readonly,
clickType: props.clickType,
onClick: props.onClick,
changeState: this.changeState,
Expand All @@ -139,6 +140,7 @@ export class Pick<S extends PickState = PickState, O extends PickOptions<S> = Pi
className: props.popClass,
style: props.popStyle,
disabled: props.disabled,
readonly: props.readonly,
changeState: this.changeState,
togglePop: this.toggle,
placement: props.popPlacement,
Expand Down
1 change: 1 addition & 0 deletions lib/pick/src/types/pick-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface PickOptions<S extends PickState = PickState> {

defaultValue?: string;
disabled?: boolean;
readonly?: boolean;
name?: string;
onChange?: (value: string, oldValue: string) => void;
onClick?: (event: MouseEvent) => void | boolean;
Expand Down
1 change: 1 addition & 0 deletions lib/pick/src/types/pick-pop-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface PickPopProps<S extends PickState = PickState> {
id: string;
state: S;
disabled?: boolean;
readonly?: boolean;
changeState: PickerStateChanger<S>;
togglePop: (open?: boolean, state?: Partial<S>) => Promise<S>;

Expand Down
1 change: 1 addition & 0 deletions lib/pick/src/types/pick-trigger-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface PickTriggerProps<S extends PickState = PickState> {
id: string;
state: S;
disabled?: boolean;
readonly?: boolean;
changeState: PickerStateChanger<S>;
togglePop: (open?: boolean, state?: Partial<S>) => Promise<S>;
onClick?: (event: MouseEvent) => void | boolean;
Expand Down

0 comments on commit 3263365

Please sign in to comment.