The correct term is "Collapse". This comes from the use of file structure trees (folders in modern speak). You "Open" a "Folder" to view it's contents, but "Expand" a "Directory"/"Folder" to "Explore" it. Expanding many Folders (it a tree) can look messy, so to keep things tidy, we Collapse them as necessary. The act of Expanding and Collapsing has to do with the "Branching" nature of these "Tree" structures.
It's also a good word for the action, since "contract" would suggest squashing, where "Collapsing" suggests 'folding up' almost like an accordion, where any amount of branching subfolders will be Collapsed back into a particular Directory or Folder.
Further evidence of this use can be seen in early versions of Microsoft Word's Document Map. The term Expand and Collapse are used to navigate sections and sub sections of the document. It is from this origin, that the term has become accepted universally as the correct antonym of "Expand".
Today, all program code can be expanded or collapsed to make sections of code easier to read (another suitable place for it since all programming code tends to have branching characteristics).