Skip to content

Commit

Permalink
fix: dropdowns now select chart carousel
Browse files Browse the repository at this point in the history
  • Loading branch information
jcw780 committed Jul 14, 2020
1 parent 3a89720 commit a65eeb9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
8 changes: 6 additions & 2 deletions src/components/Charts/Charts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,11 @@ class SubGroup extends React.Component<subGroupProps, {index: number}>{
const link = links[i];
link[T.singleLinkIndex.name] = chart[singleChartIndex.name];
if(carousel){
link[T.singleLinkIndex.ref] = this.scrollRef;
link[T.singleLinkIndex.ref] = () => {
const {current} = this.scrollRef;
if(current !== undefined || current !== null) window.scrollTo(0, current!.offsetTop);
this.handleSelectButton(String(i));
}
}else{
link[T.singleLinkIndex.ref] = chart[singleChartIndex.ref].current!.scrollRef;
}
Expand Down Expand Up @@ -294,7 +298,7 @@ export class ChartGroup extends React.Component<chartGroupProps>{
});
//Preinitialize postpenetration names
this.chartConfigs.post.forEach((chart, i) => {
chart[singleChartIndex.name] = 'Horizontal Impact Angle ' + (i + 1);});
chart[singleChartIndex.name] = `Horizontal Impact Angle $(i + 1)`;});

const initialJson = require('../../static/initialData.json');
this.updateData(initialJson, false);
Expand Down
10 changes: 7 additions & 3 deletions src/components/Navbar/NavDropdownContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@ interface propsT{
links: T.singleLinkT[], title: string,
}
export class NavDropdownContainer extends React.Component<propsT>{
private makeScroller = (ref : React.RefObject<any>) => {
private makeScroller = (ref : React.RefObject<any> | ((any) => void)) => {
const scrollToRef = (ref : React.RefObject<any>) => {
const {current} = ref;
if(current !== undefined || current !== null) window.scrollTo(0, ref.current!.offsetTop);
if(current !== undefined || current !== null) window.scrollTo(0, current!.offsetTop);
}
if(ref instanceof (Function)){
return ref;
}else{
return () => scrollToRef(ref);
}
return _ => scrollToRef(ref);
}
private makeDropdowns = () => {
return this.props.links.map((link, i) => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/commonTypes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export type chartRefT = React.RefObject<SingleChart>;

//Navbar Links
export enum singleLinkIndex {name, ref}
export type singleLinkT = [string, React.RefObject<any>];
export type singleLinkT = [string, React.RefObject<any> | ((any) => void)];
export type parameterRefT = React.RefObject<ShellFormsContainer
| TargetFormsContainer | SettingsBar>;
export type linkKeyT = chartT | 'parameters';
Expand Down

0 comments on commit a65eeb9

Please sign in to comment.