-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Slider: Convert to mergeStyles (Part #1) #4796
Conversation
renderedValue?: number; | ||
} | ||
|
||
export enum ValuePosition { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI - This seems to be unused and can be deprecated / removed in a subsequent PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm looks like a snapshot test is failing.. taking a look: FAIL src/components/Slider/Slider.test.tsx (8.835s)
● Slider › renders Slider correctly
expect(value).toMatchSnapshot()
Received value does not match stored snapshot 1.
- Snapshot
+ Received
@@ -10,11 +10,11 @@
aria-valuemin={0}
aria-valuenow={0}
aria-valuetext={undefined}
className="ms-Slider-slideBox ms-Slider-showValue ms-Slider-showTransitions undefined"
disabled={false}
- id="Slider0"
+ id="Slider1"
onKeyDown={[Function]}
onMouseDown={[Function]}
onTouchStart={[Function]}
role="slider"
type="button"
at Object.<anonymous> (src/components/Slider/Slider.test.tsx:15:18)
at new Promise (<anonymous>)
at <anonymous>
● Slider › renders a slider
TypeError: Cannot read property 'querySelector' of null
at Object.<anonymous> (src/components/Slider/Slider.test.tsx:23:38)
at new Promise (<anonymous>)
at <anonymous>
● Slider › can slide to default min/max and execute onChange
TypeError: Cannot read property 'querySelector' of null
at Object.<anonymous> (src/components/Slider/Slider.test.tsx:40:36)
at new Promise (<anonymous>)
at <anonymous>
● Slider › has type=button on all buttons
TypeError: Cannot read property 'querySelectorAll' of null
at Object.<anonymous> (src/components/Slider/Slider.test.tsx:77:36)
at new Promise (<anonymous>)
at <anonymous>
● Slider › renders correct aria-valuetext
TypeError: Cannot read property 'querySelector' of null
at Object.<anonymous> (src/components/Slider/Slider.test.tsx:101:30)
at new Promise (<anonymous>)
at <anonymous>
› 1 snapshot test failed. |
Thank you @oengusmacinog for the snapshots walk-thru! |
@@ -16,8 +18,8 @@ describe('Slider', () => { | |||
}); | |||
|
|||
it('renders a slider', () => { | |||
const component = ReactTestUtils.renderIntoDocument( | |||
<Slider label='slider' /> | |||
const component = ReactTestUtils.renderIntoDocument<SliderBase>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: that I've refactored the tests to test <SliderBase/>
as we did in 3626565
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really don't completely understand this. What is the reasoning?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was trying to follow a component's tests that followed the getStyles
pattern and were passing. Seems inconsistent tho and perhaps I followed the wrong pattern. Prior to using <SliderBase/>
the DOM wouldn't render, likely because I was omitting something that was causing <Slider/>
to throw.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re: the type parameter changes those can be removed and won't affect anything, just happened to be the pattern that I followed from 3626565 but even that is inconsistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, a few comments.
} | ||
|
||
export class SliderBase extends BaseComponent<ISliderProps, ISliderState> implements ISlider { | ||
public static defaultProps: {} = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For next PR (assuming this PR won't contain transitioning from sass to mergeStyles in the base component file): Type of defaultProps
should probably be ISliderProps
instead of {}
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a worthwhile change to make now since it could make for some hard to find bugs later. In general {}
should never be used as a type.
* Theme provided by High-Order Component. | ||
*/ | ||
theme?: ITheme; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add className?: string;
as well so consumers can add a class to the root component.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
className?
is already available its just lower in the field set
|
||
return ( | ||
<div | ||
className={ css('ms-Slider', styles.root, className, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For next PR: Make sure all this logic is in the styles file, including the globalClassNames such as "ms-Slider-enabled" etc. There shouldn't be a need for the css() function anywhere.
@JasonGore Kevin is out on leave; can we get this merge conflict fixed and clean up? Not urgent but doesn't look too bad to help out. |
Pull request checklist
$ npm run change
Description of changes
Part 1 of converting
<Slider/>
to mergeStyles, changes include:.styles.ts
file.Slider.tsx
intoSlider.base.tsx
and styledSlider.tsx
.getGlobalClassNames
introduced by Flag on theme for no global class names #4635I used the following as references (first time doing this type of refactor):
Focus areas to test
That the
<Slider/>
renders as expected w/ its styles.