Skip to content

Commit

Permalink
fix: pass an id to un/focus_input_field (#7585)
Browse files Browse the repository at this point in the history
  • Loading branch information
tracernz committed Nov 10, 2022
1 parent 882ca70 commit 2762812
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class A320_Neo_CDU_MainDisplay extends FMCMainDisplay {
Init() {
super.Init();
try {
Coherent.trigger('UNFOCUS_INPUT_FIELD');// note: without this, resetting mcdu kills camera
Coherent.trigger('UNFOCUS_INPUT_FIELD', this.scratchpad.guid);// note: without this, resetting mcdu kills camera
} catch (e) {
console.error(e);
}
Expand Down Expand Up @@ -782,7 +782,7 @@ class A320_Neo_CDU_MainDisplay extends FMCMainDisplay {
this.inFocus = false;
this.allSelected = false;
try {
Coherent.trigger('UNFOCUS_INPUT_FIELD');
Coherent.trigger('UNFOCUS_INPUT_FIELD', this.scratchpad.guid);
} catch (e) {
console.error(e);
}
Expand All @@ -808,7 +808,7 @@ class A320_Neo_CDU_MainDisplay extends FMCMainDisplay {
this.getChildById("header").style = "background: linear-gradient(180deg, rgba(2,182,217,1.0) 65%, rgba(255,255,255,0.0) 65%);";
this.scratchpad.setDisplayStyle("display: inline-block; width:87%; background: rgba(255,255,255,0.2);");
try {
Coherent.trigger('FOCUS_INPUT_FIELD');
Coherent.trigger('FOCUS_INPUT_FIELD', this.scratchpad.guid);
} catch (e) {
console.error(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class ScratchpadDisplay {

class ScratchpadDataLink {
constructor(mcdu, displayUnit) {
this.guid = `SP-${Utils.generateGUID()}`;
this._text = "";
this._message = {};
this._status = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ interface SimpleInputProps {
}

export const SimpleInput = (props: PropsWithChildren<SimpleInputProps>) => {
const [guid] = useState(`SI-${Utils.generateGUID()}`);

const [displayValue, setDisplayValue] = useState(props.value?.toString() ?? '');
const [focused, setFocused] = useState(false);

Expand Down Expand Up @@ -153,12 +155,12 @@ export const SimpleInput = (props: PropsWithChildren<SimpleInputProps>) => {

useEffect(() => {
if (focused) {
Coherent.trigger('FOCUS_INPUT_FIELD');
Coherent.trigger('FOCUS_INPUT_FIELD', guid);
} else {
Coherent.trigger('UNFOCUS_INPUT_FIELD');
Coherent.trigger('UNFOCUS_INPUT_FIELD', guid);
}
return () => {
Coherent.trigger('UNFOCUS_INPUT_FIELD');
Coherent.trigger('UNFOCUS_INPUT_FIELD', guid);
};
}, [focused]);

Expand Down
2 changes: 2 additions & 0 deletions src/instruments/src/EFB/react-app-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ declare global {
* @param args any extra arguments to be passed to the event handlers.
*/
function trigger(name: string, ...args: any[]): void;
function trigger(name: 'FOCUS_INPUT_FIELD', id: string, title?: string, description?: string, defaultValue?: string, isNumeric: boolean): void;
function trigger(name: 'UNFOCUS_INPUT_FIELD', id: string);

/**
* Add a handler for an event.
Expand Down
2 changes: 2 additions & 0 deletions typings/fs-base-ui/html_ui/JS/coherent.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ declare global {
* @param args any extra arguments to be passed to the event handlers.
*/
function trigger(name: string, ...args: any[]): void;
function trigger(name: 'FOCUS_INPUT_FIELD', id: string, title?: string, description?: string, defaultValue?: string, isNumeric: boolean): void;
function trigger(name: 'UNFOCUS_INPUT_FIELD', id: string);
/**
* Shows the debugging overlay in the browser.
* Will also work in Coherent GT only if engineForceEnableMocking is set to true.
Expand Down

0 comments on commit 2762812

Please sign in to comment.